0

I have two text files. First file have 20 Names listed in seperate lines and 2nd file have 20 surnames listed in seperated lines. How I can combine those files. So final text file have both first name and surname.

I tried paste. But it added big space between names and surnames.

$ paste name.txt surname.txt > names.txt

1 Answer 1

2

Are the inputs correlated and if so are they in the same order? If not, do you want all 400 combinations, or something else?

If you expect 20 lines of output, and your 20 lines are both files in the matching order, you probably just want:

paste -d ' ' name.txt surname.txt > names.txt

paste uses a tab character as the default output field seperator. You can learn about this with man paste in most systems.

If they aren't in the same order, you can either sort them manually, or add some field to sort on that custom field, then join them by the field. e.g.

$ cat name.txt
2 frodo
1 samwise
$ cat surname.txt
1 ganges
2 baggins
$ join -j1 <(sort -n name.txt) <(sort -n surname.txt)
1 samwise ganges
2 frodo baggins

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .