LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   AWK - Linux vs Unix? (https://www.linuxquestions.org/questions/linux-newbie-8/awk-linux-vs-unix-4175456584/)

dmesserly 04-02-2013 04:18 PM

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

rknichols 04-02-2013 04:36 PM

Quote:

Originally Posted by dmesserly (Post 4923772)
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).

dmesserly 04-02-2013 04:52 PM

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$

dmesserly 04-02-2013 05:08 PM

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!

grail 04-03-2013 01:57 AM

Remember to mark as SOLVED once you have your solution :)


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