merge two text files using bash scripts in linux -
i have 2 text files. first 1 looks this:
a b c
another file looks this:
1 2 3 4
i want use bash scripts in linux merge these 2 files each row of first file placed next rows of second file , output looks this:
a 1 2 3 4 b 1 2 b 3 4 c 1 2 c 3 4
any appreciated
you can use awk
this:
awk 'nr==fnr{a[++n]=$0; next} {for (i in a) print $0, a[i]}' file2 file1 1 2 3 4 b 1 2 b 3 4 c 1 2 c 3 4
reference: effective awk programming
Comments
Post a Comment