Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through environmental variable in awk.

Status
Not open for further replies.

tobbe

Programmer
Jan 11, 2001
4
SE
Hi!

I'm writing a large script that converts textfiles to html. The problem is that the script is supposed to check if there are textfiles to be converted on several computers. The computers names are stored in an environmental variable, like:
COMPS_TO_CHECK="comp1 comp2 comp3 ..."

In a shellscript (ksh) I would use something like:
for c in COMPS_TO_CHECK
do
--check for files---
done

but can I do this in awk? A friend of mine suggested that I might be able to pipe the variable into the script and then use that certain field, but I'm already pipeing quite a lot of data into awk so I think that it could get quite messy...

Does anyone have an idea about how to accomplish this?
Would it be easier to put the names of the computers in a text file and read them line by line?
Has anyone understood what I'm talking about?
I'm not sure myself... ;-)

Thanks in advance
/Tobbe
 
Hmmm...I /think/ I know what you're talking about ;)

This framework seems like a good start:

for c in COMPS_TO_CHECK
do
--check for files---
done

So, could you do something like this:

# Loop through each computer
for COMP in $COMPS_TO_CHECK
do
# Maybe another loop here to go through each
# relevant directory on this computer?

# Loop through each file on this computer
for FILE in $COMP
do
awk '{
# Convert file to HTML
}' $FILE
done
done

If I understand you correctly, it seems like better design to just let awk focus on the text to HTML parsing and not have it worry about dealing with computers and directory navigation and file selection.

Hope this helps,

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top