[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

    Search the Q&A Archives

Hi, I am trying to create an awk script that reads input...

<< Back to: comp.lang.awk FAQ

Question by JAMDEE
Submitted on 8/18/2003
Related FAQ: comp.lang.awk FAQ
Rating: Rate this question: Vote

I am trying to create an awk script that reads input from a file and then execute another script on the $1 of the input file until all items in the file have been processed.

I tried different ways, but here is the latest I've tried. Please help...

on Solaris 8

awk '{
(( getline tape < "coz" ) > 0)
cd directory
./runtape -e $tape

This isn't working and I don't know what else to do.  

Answer by obrienpx
Submitted on 8/19/2003
Rating:  Rate this answer: Vote
Try printing your commands & then piping the output to the shell.  The following reads each line of input_file & pipes an ls -al to the shell.

awk '/^/ { print "ls -al " $0 } ' inpfil | sh

Another way would be to use the system operator:

awk '/^/ { system ("ls -al " $0) } ' inpfil


Answer by jamdee
Submitted on 8/19/2003
Rating:  Rate this answer: Vote
Hi and Thanks for your response...Because I'm just a beginner..I'm only using any awk guides from the net. I really don't have any knowledge using awk other than that. I just started trying all of a sudden because I heard it was a good scripting and file manipulating language. Anywho...

Question in response to your answer...
With respect, how does that apply to what I'm actually trying to do because I don't exactly understand in that one line it could do what I'm hoping to accomplish? I guess I need a lil more breakdown maybe..


Answer by obrienpx
Submitted on 8/20/2003
Rating: Not yet rated Rate this answer: Vote
Awk is a very useful tool but it can be tricky to pick up.  Anyway I have tried to put together a fairly detailed example in your terms, guessing at the sort of things you were trying to do:

File coz looks like:

In directory DIRECTORY, file runtape looks like:
ls $1 $2

Running the following from the directory holding coz:

awk '/^/ { print "cd DIRECTORY; ./runtape -alt " $0 "; cd -" }' coz

produces output:
cd DIRECTORY; ./runtape -alt 233765; cd -
cd DIRECTORY; ./runtape -alt 303t01.lst; cd -
cd DIRECTORY; ./runtape -alt dd.lst; cd -

Piping this output to the shell, like so:

awk '/^/ { print "cd DIRECTORY; ./runtape -alt " $0 "; cd -" }' coz | sh

233765 not found
-rw-r--r--   1 xxxxxx    xxx           6399 Aug 21 09:34 303t01.lst
-rw-r--r--   1 xxxxxx    xxx          43860 Aug 21 09:34 dd.lst

Where file 233765 is not in DIRECTORY but the others are.

The awk command works by reading every line from file coz, and for every line that matches the regular expression  /^/ (i.e. every line), print “cd DIRECT...”

The second approach using the system operator looks like:
awk '/^/ { system ("cd DIRECTORY; ./runtape -alt " $0 "; cd -") } ' coz


Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.

Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.


FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.


<< Back to: comp.lang.awk FAQ

[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.