Computing.Net > Forums > Unix > awk script needed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk script needed

Reply to Message Icon

Name: pauljohny
Date: October 3, 2005 at 09:46:41 Pacific
OS: unix
CPU/Ram: 16g
Comment:

Hi,

I am trying to find an awk command or an unix script equivalent to do the following.

I have the following txt file

1234 script.sh param1 param2
2345 script2.sh param1 param2
... and so on

I want something that would read the above file. run the script with the parameters. Grep through the results from the script for the word not running and in case the word is present write the first field (eg 1234) into an output file.

The script has to iterate through the whole file and do this. Any ideas on how I can do it? I am trying to figure a way using awk but in vain...




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: October 3, 2005 at 12:31:26 Pacific
Reply:

Here is a way:

#!/bin/ksh

while read line
do
set - $(echo $line)
cmdstr=$2
cnt=2
while (( $cnt < $# ))
do
((cnt=cnt+1))
eval var=$(echo \$${cnt})
cmdstr="$cmdstr $var"
done
cmdstr="$cmdstr > $1"
eval "$cmdstr"
done < data.file
# end script

read each line
use set to parse the line
build the command line
execute the command using eval.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: awk script needed

tweaking William's awk script www.computing.net/answers/unix/tweaking-williams-awk-script/5174.html

awk script www.computing.net/answers/unix/awk-script/7067.html

pass 2 input files to awk script www.computing.net/answers/unix/pass-2-input-files-to-awk-script/4448.html