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

Time:01-13

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

CodePudding user response:

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

CodePudding user response:

awk can do this.

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