bash - How to awk through multiple files? -


i have hundreds of .dat file data in side , want awk them command

awk 'nr % 513 == 99' data.0003.127.dat > data.0003.127.ma.dat 

i tried write script file like

for in {1 ... 9}; i=i*3 datafile = sprintf("data.%04d.127.dat",i) outfile = sprintf("data.%04d.127.ma.dat",i)  awk 'nr % 513 == 99' datafile > outfile done 

i need 0003 0006 0009 ... files, above script doesn't work fine. error says

bash: ./ma_awk.sh: line 3: syntax error near unexpected token `(' bash: ./ma_awk.sh: line 3: `datafile = sprintf("data.%04d.127.dat",i)' 

what shall next? use ubuntu 14.04.

in bash (since v4) can write sequence expression increment:

$ echo {3..27..3} 3 6 9 12 15 18 21 24 27 

you can include leading zeros, preserved:

$ echo {0003..0027..3} 0003 0006 0009 0012 0015 0018 0021 0024 0027 

so use following:

for in {0003..0027..3};   awk 'nr % 513 == 99' "data.$i.127.dat" > "data.$i.127.ma.dat" done 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -