-   Linux - Newbie (
-   -   Error while using awk: Unmatched '. (

shivaa 12-14-2012 08:54 AM

Error while using awk: Unmatched '.
While running awk directly on terminal (not in any script), I am getting an error (I guess it's very common) if I try to use multi-liner awk code:

# nawk 'BEGIN{
Unmatched '.
# /usr/xpg4/bin/awk 'BEGIN{
Unmatched '.
# awk '
Unmatched '.

It appears all the time with all users I tried and on all distros! Since there's no pb with if I run a one-liner command:

example# awk 'BEGIN{FS=" "}; /string/ {gsub(/string/,"",$0); print $0}' infile
But if I try:

example# awk 'BEGIN{
Unmatched '.

druuna 12-14-2012 09:30 AM

Are you using a bash or (t)csh shell?

I do believe a (t)csh shell throws that error, while bash does not.

You can do the following in both shells:

awk 'BEGIN{ \
That is a space followed by a backslash with nothing after the backslash.

tronayne 12-14-2012 09:38 AM

I can't reproduce your problem with nawk (or with gawk) with the example line you've given. Perhaps a section of your infile, say 10 or 20 lines would help diagnose?

A thought: you may have unmatched quotes in your file.

A other thought: shouldn't matter ('cause nawk doesn't care about such things) but try inserting spaces; e.g.,

nawk 'BEGIN { FS=" " } /string/ {gsub(/string/,"",$0); print $0}' infile
Still another thought: is your line too long for the terminal window (probably not, but ya never know, might be getting truncated).

Yet another thought: try it in KornShell instead of C-Shell.

Hope this helps some.

shivaa 12-14-2012 11:50 AM

You're right @druuna! I was also doubtful with execution shell.
This is a pb with tcsh and traditional /sbin/sh. But worked fine with bash.
Thanks everyone!

All times are GMT -5. The time now is 09:01 PM.