LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   BASH: Each line of multiple text files gets added to one line (https://www.linuxquestions.org/questions/programming-9/bash-each-line-of-multiple-text-files-gets-added-to-one-line-831715/)

Gavin Harper 09-12-2010 11:12 AM

BASH: Each line of multiple text files gets added to one line
 
I currently have 3 files with floating point data that I wish to have in a single file with the format:

Code:

F1      F1    F3          Output

a1      b1    c1          a1 b1 c1
a2      b2    c2          a2 b2 c2
a3      b3    c3          a3 b3 c3
a4      b4    c4          a4 b4 c4

I would greatly appreciate any intuition on how to go about this.

Thank you in advance!

konsolebox 09-12-2010 12:02 PM

Code:

#!/bin/bash

{
    while read -u 3 A && read -u 4 B && read -u 5 C; do
        echo "$A $B $C"
    done
} 3<"$1" 4<"$2" 5<"$3"

save it to script.sh then run

Code:

bash script.sh F1 F2 F3 > OUTPUT

Gavin Harper 09-12-2010 12:22 PM

Thank you very very much!

Worked a charm

ghostdog74 09-12-2010 07:31 PM

paste?
Code:

$ paste file1 file2 file3


All times are GMT -5. The time now is 10:10 PM.