LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-02-2013, 04:18 PM   #1
dmesserly
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Rep: Reputation: Disabled
AWK - Linux vs Unix?


I am relatively new to Linux, but have worked on Solaris Unix for 15+ years. On an Ubuntu 12.04 system, I have written a very simple AWK script which continues to throw errors. By very simple I mean "pattern {action}" with just a few lines. I can't figure this out, unless there is a difference with AWK on Linux vs. Unix. But even that does not seem like there should be any issues. Below is the script & errors. Can you see any problems with this script?
donald$ cat PSA.awk
{
/#0/ { printf("%s %s", $2, $3) }
/#1 AT/ { printf(",%s\n", $4) }
/#1 EMA/ { printf(",%s\n", $3) }
/\// { next }
}
donald$ awk -f PSA.awk $HOME/Documents/SCACL.txt
awk: PSA.awk:2: /#0/ { printf("%s %s", $2, $3) }
awk: PSA.awk:2: ^ syntax error
awk: PSA.awk:3: /#1 AT/ { printf(",%s\n", $4) }
awk: PSA.awk:3: ^ syntax error
awk: PSA.awk:4: /#1 EMA/ { printf(",%s\n", $3) }
awk: PSA.awk:4: ^ syntax error
awk: PSA.awk:5: /\// { next }
awk: PSA.awk:5: ^ syntax error
 
Old 04-02-2013, 04:36 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by dmesserly View Post
Below is the script & errors. Can you see any problems with this script?
donald
Code:
$ cat PSA.awk
{ 
   /#0/     { printf("%s %s", $2, $3) }
   /#1 AT/  { printf(",%s\n", $4) }
   /#1 EMA/ { printf(",%s\n", $3) }
   /\//     { next }
}
donald$ awk -f PSA.awk $HOME/Documents/SCACL.txt
awk: PSA.awk:2:    /#0/     { printf("%s %s", $2, $3) }
awk: PSA.awk:2:             ^ syntax error
awk: PSA.awk:3:    /#1 AT/  { printf(",%s\n", $4) }
awk: PSA.awk:3:             ^ syntax error
awk: PSA.awk:4:    /#1 EMA/ { printf(",%s\n", $3) }
awk: PSA.awk:4:             ^ syntax error
awk: PSA.awk:5:    /\//     { next }
awk: PSA.awk:5:             ^ syntax error
Get rid of those extraneous braces. awk is trying to interpret everything within those braces as an action statement (with a null pattern that matches every line).
 
Old 04-02-2013, 04:52 PM   #3
dmesserly
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
I tried that and it just moves the syntax error over...
donald$ cat PSA.awk
{
/#0/ printf("%s %s", $2, $3)
/#1 AT/ printf(",%s\n", $4)
/#1 EMA/ printf(",%s\n", $3)
/\// next
}
donald$ awk -f PSA.awk $HOME/Documents/SCACL.txt
awk: PSA.awk:2: /#0/ printf("%s %s", $2, $3)
awk: PSA.awk:2: ^ syntax error
awk: PSA.awk:3: /#1 AT/ printf(",%s\n", $4)
awk: PSA.awk:3: ^ syntax error
awk: PSA.awk:4: /#1 EMA/ printf(",%s\n", $3)
awk: PSA.awk:4: ^ syntax error
awk: PSA.awk:5: /\// next
awk: PSA.awk:5: ^ syntax error
donald$
 
Old 04-02-2013, 05:08 PM   #4
dmesserly
LQ Newbie
 
Registered: Apr 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Rknichols

Ignore that previous post. I re-read your post and realized which braces you were referring to. I'm now getting data from the script. Thanks!
 
Old 04-03-2013, 01:57 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Remember to mark as SOLVED once you have your solution
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Awk question (but could use other basic unix command) r0tty Programming 18 05-13-2011 11:44 AM
LXer: Plain English Explanation Of An Awk Statement For Linux Or Unix LXer Syndicated Linux News 0 11-20-2008 04:20 PM
LXer: Convoluted Column Arithmetic Examples Using Awk On Linux Or Unix LXer Syndicated Linux News 0 11-19-2008 12:30 PM
LXer: Double Spacing In Awk, Perl and Shell on Linux and Unix LXer Syndicated Linux News 0 07-08-2008 06:41 AM
LXer: Simple Cumulative Math Using Awk On Unix or Linux LXer Syndicated Linux News 0 06-30-2008 01:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration