Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append a column from file2 to the end of file1

Status
Not open for further replies.

epatton

Technical User
Aug 22, 2006
10
CA
I need to append a column of data onto the end of another file:

File 2:

192121412
192121413
192121417
192121444
192121445
192121502
192121516
...

File 1:
1,192121412,651215.162,5171375.56
2,192121413,651215.291,5171375.619
3,192121417,651215.804,5171375.855
4,192121444,651219.268,5171377.446
5,192121445,651219.396,5171377.505
...

to become:

1,192121412,651215.162,5171375.56,192121412
2,192121413,651215.291,5171375.619,192121413
3,192121417,651215.804,5171375.855,192121417
4,192121444,651219.268,5171377.446,192121444
5,192121445,651219.396,5171377.505,192121445

I need to do this without resorting to the shell 'join' command - to keep a long story short, I need an awk-only solution.

~ Eric.
 
Why not simply this ?
awk -F',' '{print $0","$2}' File1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Oops, my bad. File 1 should look like this:

46,42,,,192,09:22:13,Gravelly sand/cobbles,Large cobbles,
46,42,,,192,09:22:17,Gravelly sand/cobbles,Hydroids,
46,42,,,192,09:22:44,Gravelly sand/cobbles,Hydroids,
...

Thanks,

~ Eric.
 
Could you please restate the rules with input samples and expected result ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok.

I need to append a column of data onto the end of another file:

File 2:

192121412
192121413
192121417
192121444
...

File 1:

46,42,,,192,09:22:13,Gravelly sand/cobbles,
46,42,,,192,09:22:17,Gravelly sand/cobbles,
46,42,,,192,09:22:44,Gravelly sand/cobbles,
...

to become:

46,42,,,192,09:22:13,Gravelly sand/cobbles,192121412
46,42,,,192,09:22:17,Gravelly sand/cobbles,192121413
46,42,,,192,09:22:44,Gravelly sand/cobbles,192121417
...etc

Thanks Again,

~ Eric.

 
Like this ?
awk 'FNR==NR{a[NR]=$1;next}{print $0","a[FNR]}' File2 File1 > NewFile

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
it boarders on heresy, but may I suggest a simpler solution:
Code:
paste -d '\0' file1 file2 > newFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top