Changing values with increasing numbers!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Changing values with increasing numbers!
# 1  
Old 10-11-2008
Power Changing values with increasing numbers!

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
# 2  
Old 10-11-2008
Code:
#!/bin/bash

for ((i=0;i<100;i++))
do
  eval $(printf "vmchange -m N%04d\n" $i)
done

Works with ksh93 too.
# 3  
Old 10-11-2008
Code:
cnt=1
while [[ $cnt -lt 101 ]]
do
  vmchange -m  $(printf "N%04d" $cnt )
  cnt=$(( cnt + 1 ))
done


Last edited by jim mcnamara; 10-11-2008 at 07:22 PM..
# 4  
Old 10-11-2008
If that command accepts multiple arguments it would be more efficient when run like this:

Code:
vmchange -m N0001 N0002 ... N000n

So, if your shell supports brace expansion (ksh93, zsh, bash >=3.0)
and process substitution:

Code:
xargs vmchange -m < <(printf "N%04d\n" {1..100})

If the command does not accept multiple arguments:

Code:
printf "vmchange -m N%04d\n" {1..100}|sh

Or just use a more powerful tool:

Code:
perl -le'system sprintf "vmchange -m N%04d\n",$_ for 1..100'

# 5  
Old 10-11-2008
this is using awk
Code:
 
echo " " |awk '{for(i=0;i<=100;i++){printf("vmchange -m N%04s",i);}}'

# 6  
Old 10-11-2008
You guys are great!

Thank everyone very much.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Summing up values of rows of numbers

data file contains failed=24 error=23 error=163 failed=36 error=903 i need to get a total count of each value above. i'm looking for the most efficient method to do this as the datafile i provided is just a sample. the actual data can be several hundred thousands of lines. so from... (3 Replies)
Discussion started by: SkySmart
3 Replies

2. Shell Programming and Scripting

Changing values in the first column.

I have a file which looks like this: 1 3 5 5 3 2 1 5 3 6 3 2 0 5 6 3 2 9 0 4 5 6 4 9 In the first column, instead of 1, I want to place +1 and instead of 0, I want -1 to be put. So the generated file should look like this: +1 3 5 5 3 2 +1 5 3 6 3 2 -1 5 6 3 2 9 -1 4 5 6 4 9 Just to... (9 Replies)
Discussion started by: shoaibjameel123
9 Replies

3. Shell Programming and Scripting

AWK "make a new column that include increasing numbers"

please help!!!!!! I have a file .txt that has only one column like that: 34.1 35.5 35.6 45.6 ... Now, i want to add a column in the left in which the values of this column increase by 0.4 , for example: 0.0 34.1 0.4 35.5 0.8 35.6 1.2 45.6 How can i do with awk instructions??? ... (2 Replies)
Discussion started by: tienete
2 Replies

4. Shell Programming and Scripting

Changing and swapping the Values in the files

Hi all we have a file ONE like this 12345 98765 67222 74252 76991 90091 and we have one more file TWO like huiiii 67jjjj u988 99999 uj99j 98765 hujg 7yhh ij999 78688 ijo99 74252 Now i want create THREE file which is like huiiii 67jjjj u988 12345 uj99j 98765 hujg 7yhh ij999... (2 Replies)
Discussion started by: polineni
2 Replies

5. Shell Programming and Scripting

Adding patterns with increasing numbers at the end of every line

Hi All, I have a file which has some Linux commands in every line like more 456.dat more 3232.dat more 433.dat I want to add texts like this at the end of every line: more 456.dat > 1.txt more 3232.dat > 2.txt more 433.dat > 3.txt So, that the result of more goes into 1.txt... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

sed/awk changing values

Can somebody help me out and provide me with a SED or AWK solution that converts TO_DATE CLAUSE -> TIMESTAMP I need to keep the PARTION value (HISTORY_20110417) and DATE/TIME value (2011-04-18 00:00:00) the same for every line PARTITION HISTORY_20110417 VALUES LESS THAN (TO_DATE('... (3 Replies)
Discussion started by: BeefStu
3 Replies

7. Shell Programming and Scripting

changing and appending numbers

I have a file that looks like below but i need to add the second part to the first meaning in the part where it goes from 14 to 1 in the first column to go to 14 to 15 and the same with the right side going from 2 to 1 to go to 2 to 3. THanks 1 176.587 0.015 C 1 2 57.351 ... (4 Replies)
Discussion started by: olifu02
4 Replies

8. Shell Programming and Scripting

Help in selecting line numbers between two values

Hi! I've a file as shown below 1 hello 2 how 5 are 3 you 4 hello 5 world Every statement consists of line numbers at the beginning which are not in sequence. Now I want to select all the line numbers which are present between the line numbers specified by the user.. For example... (1 Reply)
Discussion started by: abk07
1 Replies

9. UNIX for Dummies Questions & Answers

Increasing numbers in Column

I have UWIn version of Unix for Desktop. I have a file (Subtitle file of a movie) with the following format abc def ghi jkl mno pqr stuv uvw xyz The subtitles are delayed about a min or few seconds more. I want to increase it to be as shown below: abc def ghi jkl mno pqr stuv ... (4 Replies)
Discussion started by: bobbygsk
4 Replies

10. UNIX for Dummies Questions & Answers

Changing Values in the Kernel

I'm getting fork failed errors. I was told I needed to upgrade my swap space but also need to change some values for some parameters in the kernel and add 2 new parameters. I not sure of the correct way of doing this. Thanks in Advance (4 Replies)
Discussion started by: dman110168
4 Replies
Login or Register to Ask a Question