Re: for loop help (172 Views)
Reply
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 1 of 9 (172 Views)
Accepted Solution

for loop help

Hi,

I want to manipulate some data ie:

oldgemp016 to oldgemp030

I need to make these not mountable on system reboot (AIX) and the command line is

chfs -A n oldgemp

how would I sort the regular expression in a for loop??

I am kinda thinking I should

for a in `echo oldgemp0[1-3][0-9]`

however this will error on gemp010 11 12 etc becuase they dont exist.

how could this be resolved?

any help is greatly appreciated as always.

Thanks

Chris.
hello
Please use plain text.
Honored Contributor
Ralph Grothe
Posts: 2,631
Registered: ‎04-09-2000
Message 2 of 9 (172 Views)

Re: for loop help

There are many possibilities.
Will this one do?

$ i=15;while (($((i+=1))<=30));do echo oldgemp0$i;done
oldgemp016
oldgemp017
oldgemp018
oldgemp019
oldgemp020
oldgemp021
oldgemp022
oldgemp023
oldgemp024
oldgemp025
oldgemp026
oldgemp027
oldgemp028
oldgemp029
oldgemp030
Madness, thy name is system administration
Please use plain text.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 3 of 9 (172 Views)

Re: for loop help

thats great

many thanks

chris
hello
Please use plain text.
Honored Contributor
Peter Nikitka
Posts: 1,575
Registered: ‎02-10-2003
Message 4 of 9 (172 Views)

Re: for loop help

Hi,

I think there is a 'lsfs' on AIX, and I'm shure it was enough options to restrict its output to a parsable form.
Then something like
for in in `lsfs `
do
...
done

or
for in in `lsfs | grep oldgemp0[1-3][0-9]`
do
...
done

will present you only existing volumes.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Please use plain text.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 5 of 9 (172 Views)

Re: for loop help

here is an example using the lsfs command

thanks Peter for the prompt

for FS in `lsfs -c |awk -F':' '/oldgemp/ {print $1}' |sed 's/\/app\///'`
do
etc etc


again another example however if I was looking for regular expression to find all values for oldgemp016 to oldgemp030

what would be the best systax?

thanks

Chris
hello
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 6 of 9 (172 Views)

Re: for loop help

Hi Chris:

> if I was looking for regular expression to find all values for oldgemp016 to oldgemp030


You could use:

# awk '/oldgemp0[1][6-9]|[2][0-9]|30/'

Regards!

...JRF...
Please use plain text.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 7 of 9 (172 Views)

Re: for loop help

ok good - thanks all
hello
Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,978
Registered: ‎03-06-2006
Message 8 of 9 (172 Views)

Re: for loop help

>JRF: # awk '/oldgemp0[1][6-9]|[2][0-9]|30/'

I don't think the operator precedence is correct for your ERE. You need:
$ awk '/oldgemp0([1][6-9]|[2][0-9]|30)/'

Your first one finds "new20".
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 9 of 9 (172 Views)

Re: for loop help

Hi:

>Dennis: JRF I don't think the operator precedence is correct for your ERE

Good catch, thanks. You are correct, of course.

Regards!

...JRF...
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation