I have 2 files below are the values and expected output,could anyone please help.
File 1 :
A
B
C
D
E
F
FIle 2
1
2
3
Expected output:
1
A
B
C
2
E
F
G
I have 2 files below are the values and expected output,could anyone please help.
File 1 :
A
B
C
D
E
F
FIle 2
1
2
3
Expected output:
1
A
B
C
2
E
F
G
The output of this awk script happens to produce the expected output,
but it's unclear if this is a correct answer to your question:
awk 'NR==FNR{ a[NR]=$0 }NR!=FNR{ if(FNR%3==1) { print a[++i] } print $0 }' file2 file1
NR==FNR
see: an explanation of NR and FNR, the array a[]
is filled with the values found in file file2
NR!=FNR
see: an explanation of NR and FNR, here file file1
is readif(FNR%3==1) {...}
When the value if FNR%3
equals 1, print the first member of the array a[]
, and i
is incrementedThis happens to print a line from file2, and then print 3 lines from file1. After this again 1 line from file2, and 3 lines of file1. Then the process stops. Nothing is done with the 3rd line of file2.