How do I read from 2 files 1 line at a time? Say if I have file1 and file2 with following content:
file1:
line1.a
line2.a
line3.a
file2:
line1.b
line2.b
line3.b
How do I get output like this –
line1.a
line1.b
line2.a
line2.b
line3.a
line3.b
...
...
You can do it either via a pure
bashway or by using a tool calledpaste:Your files:
Pure Bash Solution using file descriptors:
<&3 tells bash to read a file at descriptor 3. You would be aware that 0, 1 and 2 descriptors are used by Stdin, Stdout and Stderr. So we should avoid using those. Also, descriptors after 9 are used by bash internally so you can use any one from 3 to 9.
Paste Utility: