Off topic:Create multiple files using awk
1
1
Entering edit mode
5.3 years ago
A_Lh ▴ 30

Hi, all

I use awk to extract rows from a text file:

awk 'NR==FNR{vals[$1];next} ($1) in vals' indiv.txt file1.txt > new_file1.txt

But how can I use the same code for multiple files ?

I can use :

awk 'NR==FNR{vals[$1];next} ($1) in vals' indiv.txt file1.txt > new_file1.txt
awk 'NR==FNR{vals[$1];next} ($1) in vals' indiv.txt file2.txt > new_file2.txt
awk 'NR==FNR{vals[$1];next} ($1) in vals' indiv.txt file3.txt > new_file3.txt
awk 'NR==FNR{vals[$1];next} ($1) in vals' indiv.txt file4.txt > new_file4.txt
awk 'NR==FNR{vals[$1];next} ($1) in vals' indiv.txt file5.txt > new_file5.txt
. . . .        .    .     .     .    .     .      .     .    .    .    .    .  
awk 'NR==FNR{vals[$1];next} ($1) in vals' indiv.txt file29.txt > new_file29.txt

But there is some ways to do it automaticaly ? for example a loop or file.txt > new_file.txt.

Thanks!

Abdel

awk bash sed grep • 1.3k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 2583 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6