shell scripting do loop -
sorry im new unix, wondering there anyway can make following code loop. example file name change every time 1 50
my script is
cut -d ' ' -f5- cd1_abcd_w.txt > cd1_rightformat.txt ; sed 's! \([^ ]\+\)\( \|$\)!\1 !g' cd1_rightformat.txt ; sed -i 's/ //g' cd1_rightformat.txt; cut -d ' ' -f1-4 cd1_abcd_w.txt > cd1_extrainfo.txt ;
i make loop cd1_abcd_w.txt become cd2_abcd_w.txt , output cd2_rightformat.txt etc...all way 50. cd$i.
many thanks
in bash
, can use brace expansion:
for num in {1..10}; echo ${num} done
similar basic for = 1 10
loop, it's inclusive @ both ends, loop output numbers 1 through 10.
you replace echo
command whatever need do, such as:
cut -d ' ' -f5- cd${num}_abcd_w.txt >cd${num}_rightformat.txt # , on
if need numbers less ten have leading zero, change expression in for
loop {01..50}
instead. doesn't appear case here it's handy know.
also in not-needed-but-handy-to-know category, can specify increment if don't want use default of one:
pax> num in {1..50..9}; echo ${num}; done 1 10 19 28 37 46
(equivalent basic for = 1 50 step 9
).
Comments
Post a Comment