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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

` is not expected. - Brand new to scripting 1

Status
Not open for further replies.

Faelcu

MIS
Oct 28, 2002
19
US
I'm trying to write a script to find all the report titles in our program directories. The key I can use for this is "w-title". My biggest problem is that the actual title may be on the next line so I need to print out both lines.

I'm brand new to scripting so there's probably something obvious in what I'm trying to do and not succeeding in. This is the first time I've ever tried to use sed or awk and my scripting is almost as limited.

I'm running on AIX 5.3.

find . -name "*.p" -type f > /home/gls/tmp-file
chmod 666 /home/gls/tmp-file
for x in `cat /home/gls/tmp-file`
do
awk '/w-title/{printf $0:next}1'$x >> /home/gls/list-titles.txt
done
chmod 666 /home/gls/list-titles.txt

I get the error "` is not expected.itles.[29]: 0403-057 Syntax error at line 32 : `do"

I've Googled, searched thru Tek-Tips, read my massive Unix book and I'm still clueless. Can anyone give me a hint of what I'm doing wrong?

Any help is greatly appreciated.
 
man grep

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I think my problem is on the 'do' line or the 'for x' line.

I changed the awk statement to
grep -i -p"." "w-title"
and get the same message.
' is not expected.itles[29]: 0403-057 Syntax error at line 31 : `do
 
Why not simply this ?
grep 'w-title' *.p > /home/gls/list-titles.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I get the same error message. And from what I've read grep won't print the two lines, just one.

find . -name "*.p" -type f|xargs grep "w-title" > /home/gls/find.doc

will give find me all the program lines in all the directories and subdirectories I'm searching, but it won't give me the second line when the definition is broken between two lines. I thought I'd need sed or awk for that. But no matter what I seem to do I keep getting the same error message.
 
And this ?
find . -name '*.p' -type f | while read f
do sed -n '/w-title/{;N;p;q;}' "$f"
done > /home/gls/list-titles.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Okay. I'm begin very dense today.... I dropped the first part of my script and ran just the 'find' command you gave me. This worked! But it didn't give me the source file names as I'd hoped. I think I've been working on this too long and I've gone blind ;->

My goal is to list the subdirectory plus source file name and the one and/or two lines defining the field I'm looking for. For some reason this seems to be beyond me.
 
Perhaps this ?
find . -name '*.p' -type f | while read f
do awk '/w-title/{x=FILENAME":"$0;getline;print x,$0}' "$f"
done > /home/gls/list-titles.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I'm looking to get something like the following except that I need two lines printed when I find "w-title" and not just one.

./csv-prtloc2.p:def var w-title as char format "x(40)" init
./csv-prtloc2.p:{repstart.i &title=w-title
./lblsxsku.p:def var w-title as char format "x(60)" no-undo.
./lblsxsku.p: w-title = "-= MAILING LABELS BY SKU =-"
./obs-prtcst.p:def var w-title as char format "x(40)" init

(The ./csv-prtloc2.p source file has the definition split between 2 lines)

Your code gives me the two lines beautifully (and I thank you very much for that!), but I still need to identify at least the source file. I've really got to find some way to do this other than manually, there are thousands of program files that have to be searched. And I'm determined to learn more about scripting and the tools available to me. And so far you're showing me all kinds of things to think about!
 
but I still need to identify at least the source file
My last awk suggestion didn't do that ?
 
My mistake. I found a typo I made. YES! Your last suggestion did EXACTLY what I need!

Consider yourself a HERO today! I greatly appreciate your help on this. It has saved me days (at least) of work.

THANK YOU
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top