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

Nawk Solaris 8 newline in string 1

Status
Not open for further replies.

derekpc

Technical User
Jul 3, 2001
44
GB
I have a ksh script that utilizes nawk to set some variables. It is running succesfully on two of my domains, one running on a SUN E250 and Solaris 7 and one on a SUN Ultra80 running Solaris 8. On my third domain, I have the same script running on an Ultra10 under Solaris 8 and on only this system, nawk errors out with a "newline in string" error.
In the following example, filelist is a newline delimited file containing the full path to each file to process. The file is the result of redirecting the output of ls -1 of all files with a specific extension
to a file named filelist.

Code:
for i in $(cat filelist);do
   SUBJ=$(nawk -F \n '
      {
         if ( sub(/^[ \t]*SUBJ(: *|\/)|^[ \t]*SUBJECT:[ ]*/, "") )
            exit
      }
      END { print } ' $i
done

The resulting error is as follows:

[highlight]
nawk: syntax error at source line1
context is
>>>/path/to/file/filname. <<< ext
nawk: bailing out at source line 1
nawk: newline in string
xport... at source line 1
[/highlight]

The ext above is the file extension. There is absolutly not a newline between the filename and the extension.
On the two domains where the script is working, I used CTRL-V CTRL-RTN to enter the newline as the field separator. On the Ultra10, something in the keymapping is preventing me from doing this, so I suspect that nawk is not getting what I expect it to get as the field separator. But, if that is the case, I really don't understand why \n is not working on a Solaris box. Can anyone shed any light?

Thanks.
Derek
 
You may try this:
for i in $(cat filelist);do
SUBJ=$(nawk 'BEGIN{FS="\n"}
{
if ( sub(/^[ \t]*SUBJ:) *|\/)|^[ \t]*SUBJECT:[ ]*/, "") )
exit
}
END { print } ' $i
done

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV. I will give it a try and let you know.
Derek
 
Thanks PHV, that did the trick. Any idea why it works properly in a BEGIN statement, but not as a command line switch?
Appreciate the assistance.
Derek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top