Issue
I was looking for a way to combine two files that are uneven, I know there is a solution with awk but I am unable to modify it to fit my need. I.E.
a
b
c
d
File 2
1
2
Solution
a:1
b:2
c:1
d:2
if the first file is 10 words and the second is only 3 words, repeat the 3 words until the end of the first file EOF, and im sure theres a delimiter flag with ':' in there.
My best attempt was:
paste -d file1 /dev/null file2 > new_file
But that only put the 1,2 in the new list but didn't repeat.
Solution
For the given sample data, you may try this awk
:
awk 'FNR == NR{a[++n]=$1; next} {print $1 ":" a[(FNR-1) % n + 1]}' file2 file1
a:1
b:2
c:1
d:2
Answered By - anubhava Answer Checked By - Marie Seifert (WPSolving Admin)