开发者

Applying same command on different input files to different output files

开发者 https://www.devze.com 2023-03-28 01:53 出处:网络
I\'m doing $ cut -f 1,5,6 myfile1.csv > myoutput1.csv $ cut -f 1,5,6 myfile2.csv > myoutput2.csv $ cut -f 1,5,6 myfile3.csv > myoutput3.csv

I'm doing

$ cut -f 1,5,6 myfile1.csv > myoutput1.csv
$ cut -f 1,5,6 myfile2.csv > myoutput2.csv
$ cut -f 1,5,6 myfile3.csv > myoutput3.csv

...

Suppose I have开发者_高级运维 400 files, I want to write just one command for the 400 files, it seems that cut doesn't support specifying output filenames? I'm sure I'm missing a command here, but I couldn't guess how to use xargs here, any ideas?


for i in `seq 1 3`; do cut -d, -f1,5,6 "myfile${i}.csv" > "myoutput${i}.csv"; done

To handle arbitrary filenames, try this:

for filename in `find . -maxdepth 1 -name '*.csv' | cut -d/ -f2 | cut -d. -f1`
do
    cut -d, -f1,5,6 "${filename}.csv" > "${filename}.out.csv"
done

Yet another way to skin this cat:

for filename in `find -name '*.csv' -exec basename "{}" \;`
do
    cut -d, -f1,5,6 $filename > ${filename/.csv}.out.csv
done
0

精彩评论

暂无评论...
验证码 换一张
取 消