Youssef Hammouma
Youssef Hammouma

Reputation: 151

In bash script how to merge 2 Multi lines files in one file

I have a file 1 :

ZRFYOK5U
 H8X7IS5G
 8TV7N4BK

And a file 2 :

1
4138
1167

I'd like to merge them so it looks like this :

ZRFYOK5U;1
 H8X7IS5G;4138
 8TV7N4BK;1167

Upvotes: 0

Views: 60

Answers (2)

Kent
Kent

Reputation: 195039

As mentioned in the comments under the question, paste is pretty straightforward to solve this problem:

paste -d ';' file1 file2

Example:

$  paste -d ';' <(seq 5 ) <(seq 6 10)
1;6
2;7
3;8
4;9
5;10

Upvotes: 1

gchfeng
gchfeng

Reputation: 28

awk can do this.

awk 'NR==FNR{a[FNR]=$0}NR>FNR{print a[FNR]";"$0}' file1 file2 > output.txt

Upvotes: 0

Related Questions