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!

AWK error 1

Status
Not open for further replies.

curious01

Technical User
Feb 22, 2006
13
SG
Hi,
I am very lost with the errors I get when I execute a previously used command. Though it worked before but now a problem. Is single quote not allowed on some machines? Can anyone help me?

The error message is:
syntax error near line 1
bailing out near line 1

The script I used is:

awk '
NR==FNR {a[$1]=$1;b[$1]=$2; next}
$1 in a {print a[$1],$2}
'TableA.txt TableB.txt
Thank you

curious1
 
Hi

curious01 said:
Though it worked before but now a problem.
What happened since then ? Any input file changed ?
curious01 said:
Is single quote not allowed on some machines?
That is matter of shell.

Works for me with [tt]gawk[/tt] and [tt]mawk[/tt] runned from [tt]bash[/tt].

Maybe you have a strange Unix version of [tt]awk[/tt], which does not support blank lines. Try to remove them :
Code:
awk 'NR==FNR {a[$1]=$1;b[$1]=$2; next}
$1 in a {print a[$1],$2}' TableA.txt TableB.txt
By the way, you had no space between the code and the first file name. But probably that was just a typo in the posted copy.

Feherke.
 
on first glance, you need a space between the final ' and the first file name like so:

awk '
NR==FNR {a[$1]=$1;b[$1]=$2; next}
$1 in a {print a[$1],$2}
' TableA.txt TableB.txt

also, the ' chars can be on the same line as the first/last AWK code characters like so:

awk 'NR==FNR {a[$1]=$1;b[$1]=$2; next}
$1 in a {print a[$1],$2}' TableA.txt TableB.txt



HTH,

p5wizard
 
Thank you Feherke and p5wizard.
I 've tried both your suggestions but I still get the error message. When I execute using nawk I get error saying:
syntax error at source line 1.
context is awk >>> ' <<<
nawk bailing out at source line 1

So does that mean single quote is an invalid char to use?
How can I substitute this? Your help will be much much appreciated :)
Thanks again

curious1
 
Get rid of the #! line you seem to have in your script.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi Feherke and PHV,
Thanks for your response. I am using the bash shell and do not have #! in my script. Do I need to modify my script?

Thanks :)

curious1
 
Why not posting the WHOLE content of the script file inside [ignore]
Code:
 and
[/ignore] tags and how you launch it from bash ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,
I'm sorry, I am still very new to AWK etc. May I ask what does it mean inside
Code:
 and
tags? Well I lauch using : awk -f scriptfile > outfile

Thanks :)

curious01
 
Also then the word "awk" and the single quotes should not be in your scriptfile

scriptfile:
NR==FNR {a[$1]=$1;b[$1]=$2; next}
$1 in a {print a[$1],$2}

launch:
awk -f scriptfile TableA.txt TableB.txt >outfile

without a script file, launch like so:
awk 'NR==FNR {a[$1]=$1;b[$1]=$2; next}
$1 in a {print a[$1],$2}' TableA.txt TableB.txt >outfile



HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top