Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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