Reputation: 28319
Having file with no delimiters between columns:
cat file_no_del
aba14092999140932436
aba1111478991111484975
aba1111973668111975690
How to extract those lines from the original file (with delimiters between columns)? And save it in a new file with delimited columns?
cat original_file
aba1 40929991 40932436
aba1 100496122 100501188
aba1 101708714 101709305
aba1 111478991 111484975
aba1 111973668 111975690
cat wanted_output
aba1 40929991 40932436
aba1 111478991 111484975
aba1 111973668 111975690
I was thinking that it might be possible to do it like this:
for i in $(sort orginal_file); do awk '{print $1$2$3}' $i | grep -w - file_no_del
But I am having problems with awk & don't know how after greping I should come back in the loop to delimited form.
Hope someone can help me with this.
Upvotes: 0
Views: 89
Reputation: 212208
If file_no_del
is small enough, just do:
awk 'NR==FNR{ a[$0]++ } NR!=FNR && a[$1 $2 $3]' file_no_del original_file
Upvotes: 2