Visit Our UNIX and Linux User Community


AWK Syntax errors :/


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Syntax errors :/
# 1  
Old 06-08-2005
AWK Syntax errors :/

I recently started as an intern and my manager wanted to see how well I would handle Korn Bourne shell scripting without any prior experience, I have prior programming experience but I keep running into syntax errors with AWK. Please take a look at my simple code and tell me what stupid mistake I'm doing.

From Telnet:
awk -F, -f app_kpi_001.pgm test_file.csv
awk: syntax error near line 1
awk: bailing out near line 1

Contents of app_kpi_001.pgm:
BEGIN { FS="," }
$1 ~ /PBR/ { print $1 }
END { print "Done" }

This script itself is useless, I'm trying to play around with it so that I'm familiar with it. I have this CSV file which I will have to take as the input and create some pretty lengthy and complicated operations on between BEGIN and END to monitor key performance indicators. Any help is greatly appreciated as I'm new and eager to learn. There is no training here (which is what I thought they'd give me since I'm an intern).
# 2  
Old 06-08-2005
if on Solaris, try using 'nawk' instead of 'awk'.
# 3  
Old 06-08-2005
Hmm...

I just asked someone on the floor if the server is on Solaris, and yes it is. Here's the result of using nawk instead of awk.

From Telnet:
nawk -F, -f app_kpi_001.pgm test_file.csv
nawk: syntax error at source line 1
context is
<<< BEGIN { FS="," >>> }
nawk: bailing out at source line 1

Content of app_kpi_001.pgm:
BEGIN { FS="," }
$1 ~ /PBR/ { print $1 }
END { print "Done" }

Is there something obviously wrong with my code? Hmm..
I have the "UNIX in a NUTSHELL" book in front of me which I've been reading since yesterday, it has Korn and Bourne shell chapter and I've also been googling around for awk syntax since yesterday hm.

Last edited by yongho; 06-08-2005 at 03:39 PM..
# 4  
Old 06-08-2005
works just fine on Solaris 8
Make sure you have no hidden control characters anywhere in the file - in particular the first line.
# 5  
Old 06-08-2005
ah... Hmm..

Thank you for checking for me.
Now that I know that the code works, I'm looking elsewhere for the cause of error.

I've been using a program on Windows called Editplus, it's supposed to be plain TXT and nothing else. And I've just been uploading that file to the server via FTP. I thought at first it might be because maybe editplus was using "hard" tabs, but I switched them to "soft" tabs.. I'll try to see if I can find any hidden characters that may be screwing with the code.
# 6  
Old 06-08-2005
make sure you ftp to Sun in 'ascii' mode.
# 7  
Old 06-08-2005
MySQL ahh, very good, very good

You're absolutey right.
That was the cause of the problem.

I VI'ed the file and noticed that there was a hidden "^M" character at the end of each line. Switching my ftp client to ascii mode (as opposed to auto mode) fixed the problem.

Thank you, I appreciate your help in this time-consuming matter.

And now, I can begin coding my assignment, the real hard part begins for me.

Previous Thread | Next Thread
Test Your Knowledge in Computers #15
Difficulty: Easy
UDP is a connection-oriented protocol.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding latest file in dir but getting syntax errors

I believe there are couple of syntax issues in my script, couldn't find them :( can someone help me with fixing it to make it work. cd /abcde/ #get the latest filename excluding subdirs filename=`ls -ltr | grep ^- | tail -1 | awk '{print $8}'` #get system date and file timestamp and... (3 Replies)
Discussion started by: simpltyansh
3 Replies

2. Homework & Coursework Questions

Help with shell scrip syntax errors

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This script will analyse the channels.txt e registrations.txt and it will allow to mage the channels and the... (9 Replies)
Discussion started by: Demas
9 Replies

3. Shell Programming and Scripting

Converting from Linux bash (GNU) to Solaris script syntax errors

Original script written on CentOS 6.3 with GNU bash 4.1.2 Destination system is Solaris 9 with GNU bash 2.05 (not changeable by me) I have a script written on the linux side but now we need to provide a version to another site that "doesn't like linux". I've been going through changing the ] or... (13 Replies)
Discussion started by: oly_r
13 Replies

4. Programming

Errors in Perl when using awk command

Hi Guys, Hope everyone is fine :) I have this code below: #!/usr/bin/perl $num_of_files=`ls | grep -v remover | wc -l`; $remover=`ls -lrt | grep -v total | grep -v remover | head -1 | awk '{print $8}' | rm \`xargs\``; if ($num_of_files>3) { system ($remover); } When I... (3 Replies)
Discussion started by: rymnd_12345
3 Replies

5. Emergency UNIX and Linux Support

Seek help on shell script syntax errors

I want to delete archivelog files that has been archived and applied from primary database to standby database. This piece of script is working in Linux server. However, I copy it to Unix server with tiny modification. It won't work and generate the error message. I have checked code carefullt... (8 Replies)
Discussion started by: duke0001
8 Replies

6. Shell Programming and Scripting

line count with if /else - syntax errors

this is the script: ps -ef|grep "x_jobstat 10 v001" > jobstatv001.txt ps -ef |grep "x_jobserver 10 v001" >> jobstatv001.txt #Sample text - each line preceded by 4 spaces # root 133064 102986 0 08:49:28 pts/6 0:00 grep x_jobstat 10 v001 # root 137550 1 0 Nov 08 - 0:28... (6 Replies)
Discussion started by: kwalkner
6 Replies

7. UNIX for Dummies Questions & Answers

I dont really think that the math header has syntax errors

Hi, Mini:Evaluator develop$ make bison -d grammar.y grammar.y: conflicts: 24 shift/reduce flex rules.l cc -0 -o Evaluator grammar.tab.c lex.yy.c -ly -ll -lm In file included from grammar.y:3: /usr/include/architecture/i386/math.h:310: error: syntax error before numeric constant... (1 Reply)
Discussion started by: tcerka
1 Replies

8. Shell Programming and Scripting

PERL Syntax Errors

Hi, I am a newbie to PERL and working on a script. When running it I get a lot of compilation errors. The actual command in the program (which is within a case structure) is given below # This gives the actual count of inquires from a log file (It works fine when I type this on the... (2 Replies)
Discussion started by: nurani
2 Replies

9. Shell Programming and Scripting

perl version for syntax errors

All, Does it matter what perl verios your running when you get syntax errors? on version 5.6.1 the code works fine, but on 5.8.0 the code gets errors? #!/usr/bin/perl #use strict; #use warnings; my $mess = 'messages'; my $mess1 = 'messages.1'; my $mess2 = 'messages.2'; my... (13 Replies)
Discussion started by: bigben1220
13 Replies

10. Shell Programming and Scripting

awk errors

Hello, Can you please let me know how to find all lines that don't begin with pattern1, pattern2, pattern3 and pattern4? Here is my awk script that gives an error. awk 'BEGIN { NAME="$FILE" GSNO=0 } /^ISA/ { FIRST=$0; LAST="IEA*1*" +... (4 Replies)
Discussion started by: billy5
4 Replies

Featured Tech Videos