Home > Archive > AWK > April 2007 > Phantom "newline" character?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Phantom "newline" character?
|
|
| Greg Michael 2007-04-30, 6:57 pm |
| Hello all.
I am receiving this error message from my HPUX system when I try to set
the value of a variable using the following awk script. The awk script
itself works fine from the command line. As soon as I try to set its
output to be the value of a variable, it gives me that error.
Can anyone provide some insight on this problem?
Error:
awk: The string ,$1) cannot contain a newline character.
The source line is 3.
The error context is
gsub(/\/,"/",$1) >>>
<<<
syntax error The source line is 5.
awk: The statement cannot be correctly parsed.
The source line is 5.
awk: There is a missing ) character.
Script:
NUMFILES=`awk 'BEGIN { RS = "" }
$1 ~ /\.\\.*\\backups:/ {
gsub(/\\/,"/",$1)
gsub(/^\.\/|:$/,"",$1)
dir = $1
if (dir !~ /^T[0-9]{4}\/backups/) { next }
else {
count = split($0,files," ")
for (i=0;i<=count;i++) {
if (files[i] ~ /pospoll\..../) { filecnt++ }
}
}
}
END { print filecnt }' ./data/posfile_maint.dirlist`
Contents of posfile_maint.dirlist:
..\R0004:
05-23-03 10:52AM 438 comment.dat
09-30-04 06:34PM 512 nodeinit.dat
..\S9999:
05-23-03 10:52AM 512 nodeinit.dat
..\T0064:
04-30-07 10:31AM <DIR> backups
07-24-03 03:08PM 448 comment.dat
09-30-04 06:34PM 1536 nodeinit.dat
04-20-07 02:48PM <DIR> process
..\T0064\backups:
12-27-04 07:59PM 20368 pospoll.002
12-26-04 08:43PM 31824 pospoll.004
12-24-04 07:54PM 45914 pospoll.008
..\T0078:
04-30-07 10:31AM <DIR> backups
07-24-03 03:08PM 448 comment.dat
09-30-04 06:34PM 1536 nodeinit.dat
04-20-07 02:48PM <DIR> process
..\T0078\backups:
01-20-05 01:02AM 46710 pospoll.001
01-18-05 09:27PM 26457 pospoll.004
01-17-05 09:09PM 31431 pospoll.006
01-04-05 09:13PM 28908 pospoll.end
..\T0081:
04-30-07 10:31AM <DIR> backups
05-05-06 08:17PM 448 comment.dat
05-05-06 08:17PM 1536 nodeinit.dat
04-20-07 02:48PM <DIR> process
..\T0081\backups:
05-06-06 02:07PM 76088 pospoll.004
05-05-06 05:35PM 58868 pospoll.006
| |
| Ed Morton 2007-04-30, 6:57 pm |
| Greg Michael wrote:
> Hello all.
>
> I am receiving this error message from my HPUX system when I try to set
> the value of a variable using the following awk script. The awk script
> itself works fine from the command line. As soon as I try to set its
> output to be the value of a variable, it gives me that error.
>
> Can anyone provide some insight on this problem?
It's sometimes useful when posting a question to post the smallest
example you can of the problem rather than just whatever large script
happens to produce it. In this case (using GNU awk):
$ echo "a\b" | awk 'gsub(/\\/,"/")'
a/b
$ x=`echo "a\b" | awk 'gsub(/\\/,"/")'`; echo "$x"
awk: gsub(/\/,"/")
awk: ^ unterminated string
$ x=$(echo "a\b" | awk 'gsub(/\\/,"/")'); echo "$x"
a/b
and see your shells man page for how the two styles of command
substitution behave differently wrt backslashes.
Ed.
| |
| Greg Michael 2007-04-30, 6:57 pm |
| Ed Morton wrote:
>
> It's sometimes useful when posting a question to post the smallest
> example you can of the problem rather than just whatever large script
> happens to produce it. In this case (using GNU awk):
>
> $ echo "a\b" | awk 'gsub(/\\/,"/")'
> a/b
> $ x=`echo "a\b" | awk 'gsub(/\\/,"/")'`; echo "$x"
> awk: gsub(/\/,"/")
> awk: ^ unterminated string
>
> $ x=$(echo "a\b" | awk 'gsub(/\\/,"/")'); echo "$x"
> a/b
>
> and see your shells man page for how the two styles of command
> substitution behave differently wrt backslashes.
>
> Ed.
Ironically, it appears to have been a two-fold problem. First part was
solved by using your "$(...)" syntax noted above. Thanks. The second was
apparently caused by using Notepad as a scratch pad for testing code
changes as I wrote them. I changed it over (manually typed out) to
WordPad, which usually does not include CR/LF character sequences, and
it worked.
FYI, I did look at the man pages for Korn shell, in regards to quoting
and escape sequences. I didn't find anything that immediately made any
sense in regard to this problem, but I will remember to look at it again
in the future if I have a problem that seems to be occurring from quoting.
Thanks again Ed.
|
|
|
|
|