example: have below test script
#!/bin/bash output1=$(cat ~/desktop/scripts/test) output2=$(cat ~/desktop/scripts/test2 |sed -e 's/^/\t/g') echo -e "$output1 $output2"
when execute above script getting below output
1234 5678 9123 ndfkjdskjgbsd sdnbfksdjgkjdsb sdnbvksd dbvksdbgf
but looking output below, how can achieve?
1234 ndfkjdskjgbsd 5678 sdnbfksdjgkjdsb 9123 sdnbvksd dbvksdbgf
use paste
:
paste ~/desktop/scripts/test ~/desktop/scripts/test2
however, if really want in native shell exercise:
while ifs= read -r line1 <&3; ifs= read -r line2 <&4; [[ $line1 || $line2 ]]; printf '%s\t%s\n' "$line1" "$line2" done 3<~/desktop/script/test 4<~/desktop/script/test2
this works opening first file on fd 3, second file on fd 4, , working through both files line-by-line until there's no new content available either.
Comments
Post a Comment