1748014 Members
4600 Online
108757 Solutions
New Discussion юеВ

Re: for loop help

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

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
8 REPLIES 8
Ralph Grothe
Honored Contributor
Solution

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
lawrenzo_1
Super Advisor

Re: for loop help

thats great

many thanks

chris
hello
Peter Nikitka
Honored Contributor

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"
lawrenzo_1
Super Advisor

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
James R. Ferguson
Acclaimed Contributor

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...
lawrenzo_1
Super Advisor

Re: for loop help

ok good - thanks all
hello
Dennis Handly
Acclaimed Contributor

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".
James R. Ferguson
Acclaimed Contributor

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...