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!

Can I Concatenate the lines with the same line# from 2 different files

Status
Not open for further replies.

kobewins

Programmer
Dec 1, 2005
57
US
Hi,

I need to concatenate the lines with the same line# from 2 different file(as following). The Output_File is what I would like to have. How I do it?

Thanks
David

---
FileA
1
2
3
4

FileB
Something --> 123A...
Thething --> 234B...
otherThing --> 222C
Nothing --> 321C

Output_File
1 Something --> 123A...
2 Thething --> 234B...
3 otherThing --> 222C
4 Nothing --> 321C
 
See if you have "paste".

Code:
$ cat file1
1
2
3
4
$ cat file2
Something
SomethingElse
More Stuff
Enought
$ paste file1 file2 >file3
$ cat file3
1       Something
2       SomethingElse
3       More Stuff
4       Enought

You can modify the paste behavior to use something besides a TAB to link the lines together.
 
paste -d' ' FileA FileB >Output_File

Also have a look at the man page for paste.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top