Wednesday, May 30, 2007

[Work] Bash shell programming

shell script file: test.sh (chmod +x test.sh)
#!/bin/bash
...

//bash
for i in *.ppm; do if (test$i = "pic039.ppm"); then break; fi; echo $i; mv $i ./group00; done

#!/bin/bash
flag='0'
for i in *.ppm; do
if (test $i = "pic050.ppm")
then
flag='1'
fi
if (test $flag -gt '1')
then
echo $i
# mv $i ../
fi
done

//bash
flag="false"; for i in *.ppm; do if(test $i = "pic050.ppm"); then flag="true"; fi; if(test $flag = "true");then echo $i; fi; done

ls | wc -l
ls > ./tmp

//bash
//rename files
idx=0; for i in *.ppm; do filename=pic$(printf "%03d" $idx).ppm; let idx=idx+1; echo $filename; mv $i tmp/$filename; done

using renamer

#!/bin/sh
i=0
while [ $i -lt 1000 ]
do
i=$((i+1))
fname=$(printf "%05d" $i)
fname=horse01_${fname}_000.tif

if [ -f $fname ]
then
echo processing $fname
newname=edge_$(printf "%05d" $i)
echo newname: $newname
./linemax $fname $newname 1000
fi
done

No comments: