oduth
1
Hi all,
i have a command named "vmchange" and i must use it for thousands of data which must be changed.
For example,
vmchange -m N0001
vmchange -m N0002
vmchange -m N0003
...
...
vmchange -m N0100
How can i do that in awk or bash script?
Any help would be greatly appreciated..
thanks already
#!/bin/bash
for ((i=0;i<100;i++))
do
eval $(printf "vmchange -m N%04d\n" $i)
done
Works with ksh93 too.
cnt=1
while [[ $cnt -lt 101 ]]
do
vmchange -m $(printf "N%04d" $cnt )
cnt=$(( cnt + 1 ))
done
If that command accepts multiple arguments it would be more efficient when run like this:
vmchange -m N0001 N0002 ... N000n
So, if your shell supports brace expansion (ksh93, zsh, bash >=3.0)
and process substitution:
xargs vmchange -m < <(printf "N%04d\n" {1..100})
If the command does not accept multiple arguments:
printf "vmchange -m N%04d\n" {1..100}|sh
Or just use a more powerful tool:
perl -le'system sprintf "vmchange -m N%04d\n",$_ for 1..100'
this is using awk
echo " " |awk '{for(i=0;i<=100;i++){printf("vmchange -m N%04s",i);}}'
oduth
6
You guys are great!
Thank everyone very much.