The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ftp errors Approx.Purified UNIX for Dummies Questions & Answers 1 02-15-2008 04:06 PM
Major OS errors/Bash errors help!!!! wcmmlynn UNIX for Dummies Questions & Answers 12 11-13-2007 01:50 AM
Adapter Errors and Link Errors mcastill66 AIX 2 08-02-2005 03:51 PM
Adapter Errors and Link Errors mcastill66 UNIX for Advanced & Expert Users 0 08-02-2005 03:11 PM
awk errors billy5 Shell Programming and Scripting 4 06-22-2005 03:30 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-08-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
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).
Reply With Quote
Forum Sponsor
  #2  
Old 06-08-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
if on Solaris, try using 'nawk' instead of 'awk'.
Reply With Quote
  #3  
Old 06-08-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
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 10:39 AM.
Reply With Quote
  #4  
Old 06-08-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
works just fine on Solaris 8
Make sure you have no hidden control characters anywhere in the file - in particular the first line.
Reply With Quote
  #5  
Old 06-08-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
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.
Reply With Quote
  #6  
Old 06-08-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
make sure you ftp to Sun in 'ascii' mode.
Reply With Quote
  #7  
Old 06-08-2005
Registered User
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Thumbs up 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.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0