LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Error while using awk: Unmatched '. (http://www.linuxquestions.org/questions/linux-newbie-8/error-while-using-awk-unmatched-4175441449/)

shivaa 12-14-2012 08:54 AM

Error while using awk: Unmatched '.
 
Hello,
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:
Code:

# nawk 'BEGIN{
Unmatched '.
OR
# /usr/xpg4/bin/awk 'BEGIN{
Unmatched '.
OR
# 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:
Code:

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

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:
Code:

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.,
Code:

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 10:07 PM.