Computing.Net > Forums > Unix > need to use input file

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.

need to use input file

Reply to Message Icon

Name: Robert Pearson
Date: December 18, 2002 at 12:56:22 Pacific
OS: solaris
CPU/Ram: unknown
Comment:

I need to run the following command in a script, but I need to replace the 603528 with an input file.

bpmedialist -ev 603528|grep 'Server Host'|awk '{print 603528,$4}'>list.txt


this is what the input file looks like...

603528
605125
608452
609553



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: December 18, 2002 at 16:14:54 Pacific
Reply:

Since the loop will write multiple times to list.txt, it specifies a double right-angle bracket which will append. If a single right-angle bracket were used, each iteration of the loop would overwrite the contents. But to keep from appending the output to a previous execution, the script begins by removing list.txt.

#!/bin/sh
rm list.txt 2> /dev/null
for fname in `cat inputfile`
do
bpmedialist -ev $fname|
grep 'Server Host'|
awk -v fname=$fname '{print fname,$4}'>>list.txt
done
exit 0


0

Response Number 2
Name: Robert Pearson
Date: December 23, 2002 at 12:22:02 Pacific
Reply:

This doesnt work. I get this error message. Any ideas?

awk: syntax error near line 1
awk: bailing out near line 1


FourSKY


0

Response Number 3
Name: James Boothe
Date: January 4, 2003 at 07:35:14 Pacific
Reply:

Original awk did not support the -v option. On some platforms, the newer version of awk is nawk.


0

Sponsored Link
Ads by Google
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: need to use input file

How to use sed editor in a shell script www.computing.net/answers/unix/how-to-use-sed-editor-in-a-shell-script/8509.html

C shell unix script file www.computing.net/answers/unix/c-shell-unix-script-file/4444.html

Script to chmod today's files... www.computing.net/answers/unix/script-to-chmod-todays-files/4299.html