The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Converting Binary decimal coded values to Ascii Values gaur.deepti UNIX for Advanced & Expert Users 3 04-02-2008 12:33 PM
increasing /var roguekitton SUN Solaris 0 10-19-2007 07:26 AM
Help on increasing fs size kingsto88 HP-UX 5 02-11-2007 07:37 AM
memory increasing Frank2004 High Level Programming 0 10-21-2005 10:40 PM
Changing Values in the Kernel dman110168 UNIX for Dummies Questions & Answers 4 04-15-2001 04:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-11-2008
oduth oduth is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 7
Red face 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 (permalink)  
Old 10-11-2008
jlliagre jlliagre is offline Forum Advisor  
ɹǝsn sıɹɐlosuǝdo
  
 

Join Date: Dec 2007
Location: Paris
Posts: 1,411
Code:
#!/bin/bash

for ((i=0;i<100;i++))
do
  eval $(printf "vmchange -m N%04d\n" $i)
done
Works with ksh93 too.
  #3 (permalink)  
Old 10-11-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
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 06:22 PM..
  #4 (permalink)  
Old 10-11-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,860
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 (permalink)  
Old 10-11-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,391
this is using awk
Code:
 
echo " " |awk '{for(i=0;i<=100;i++){printf("vmchange -m N%04s",i);}}'
  #6 (permalink)  
Old 10-11-2008
oduth oduth is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 7
You guys are great!

Thank everyone very much.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0