awk problem - erroring out - unexpected token


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 05-09-2014
awk problem - erroring out - unexpected token

can anyone help identify where the issue is here?

Code:
awk 'BEGIN { c="perl -e 'print scalar(localtime("'${EPOCHTIME}'")), "\n"'"; c|getline; close( c ); print $2" "$3" "$4" "$6; }'

bash: syntax error near unexpected token `('

can't seem to figure it out. i tried this:

Code:
awk 'BEGIN { c='perl -e 'print scalar(localtime("'${REFEPOCH}'")), "\n"''; c|getline; close( c ); print $2" "$3" "$4" "$6; }'

awk: line 2: missing } near end of file

linux,sunsolaris,hpux,aix
# 2  
Old 05-09-2014
The problem is with how you're using single quotes in the shell. The first blank after the second quote ends the awk script. A quick search for how to correctly escape single quotes in the shell should help you resolve the issue.

Regards,
Alister
# 3  
Old 05-09-2014
Quote:
Originally Posted by alister
The problem is with how you're using single quotes in the shell. The first blank after the second quote ends the awk script. A quick search for how to correctly escape single quotes in the shell should help you resolve the issue.

Regards,
Alister
i have already tried searching online which is why i'm posting it here.

---------- Post updated at 06:22 PM ---------- Previous update was at 02:49 PM ----------

does anyone know how this can be fixed?

i've practually tried everything i can think of:

Code:
369  awk 'BEGIN { c="perl -e 'print scalar(localtime("1399663974")), "\n"'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  370  awk 'BEGIN { c="perl -e \'print scalar(localtime("1399663974")), "\n"'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  371  awk 'BEGIN { c="perl -e \'print scalar(localtime("1399663974")), "\n"\'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  372  awk 'BEGIN { c="perl -e \\'print scalar(localtime("1399663974")), "\n"\\'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  373  awk 'BEGIN { c="perl -e print scalar(localtime("1399663974")), "\n"" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  374  awk 'BEGIN { c="perl -e print scalar(localtime("1399663974")), "\\n"" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  375  awk 'BEGIN { c="perl -e print scalar(localtime("1399663974"))," ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  376  awk 'BEGIN { c="perl -e print scalar(localtime("1399663974"))" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  377  awk 'BEGIN { c="perl -e 'print scalar(localtime("1399663974"))'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  378  awk 'BEGIN { c=/"perl -e 'print scalar(localtime("1399663974"))'"/ ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  379  awk 'BEGIN { c="perl -e 'print scalar(localtime("1399663974"))'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  380  awk 'BEGIN { c="perl -e $'print scalar(localtime("1399663974"))'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  381  awk 'BEGIN { c="perl -e 'print scalar(localtime("1399663974"))'" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'
  382  awk 'BEGIN { c="perl -e "'"print scalar(localtime("1399663974"))"'"" ; c|getline; close( c ); print $2" "$3" "$4" "$6; }'

# 4  
Old 05-09-2014
Instead of trying to execute the perl program inside awk you can simply pipe the output to awk:
Code:
perl ... | awk '{ print $2" "$3" "$4" "$6; }'

OR in gawk, use strftime function:
Code:
awk 'BEGIN {print strftime("%b %d %H:%M:%S", "1399663974")}'

This User Gave Thanks to Yoda For This Post:
SkySmart (05-09-2014)
# 5  
Old 05-09-2014
two examples of how it could be done with your setup:
Code:
awk 'BEGIN{c="perl -le '\''print scalar(localtime(\"1399663974\"))'\''"; c|getline; close(c); print $2,$3,$4,$6}'

or:
Code:
awk -v c="perl -le 'print scalar(localtime(\"1399663974\"))'" 'BEGIN{c|getline; close(c); print $2,$3,$4,$6}'

This User Gave Thanks to Scrutinizer For This Post:
SkySmart (05-09-2014)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Syntax error near unexpected token Kamesh G UNIX for Beginners Questions & Answers 1 05-01-2018 04:21 AM
Syntax error near unexpected token 'do' gillesi UNIX for Beginners Questions & Answers 3 01-03-2018 01:33 PM
Syntax error near unexpected token `(' ranabhavish How to Post in the The UNIX and Linux Forums 1 05-09-2017 09:10 AM
For loop - unexpected token `do Ram Kumar_BE Shell Programming and Scripting 11 08-28-2015 03:45 PM
Syntax error near unexpected token `|' Meacham12 Shell Programming and Scripting 7 11-26-2013 01:50 PM
Syntax error near unexpected token '(' sgradywhite Shell Programming and Scripting 7 09-15-2013 03:37 PM
Syntax error near unexpected token `else' Aryan12345 Shell Programming and Scripting 6 05-23-2013 01:09 PM
Syntax error near unexpected token `}' please help Fisheh Shell Programming and Scripting 6 06-08-2011 12:09 PM
Syntax error near unexpected token engr.jay UNIX for Dummies Questions & Answers 6 09-27-2010 01:35 AM
Unexpected Token Error `;;' raghunsi Shell Programming and Scripting 13 09-23-2010 04:14 AM
Syntax error near unexpected token `done' Lenora2009 Shell Programming and Scripting 21 04-27-2010 10:00 PM
Syntax error near unexpected token `(' raghunsi Shell Programming and Scripting 7 02-03-2010 06:40 AM
Syntax error near unexpected token tomailraj UNIX for Advanced & Expert Users 2 08-23-2009 10:07 AM
sh syntax error unexpected token done NullPointer Shell Programming and Scripting 5 04-30-2009 10:28 AM
While loop error: Unexpected token done warlock129 Shell Programming and Scripting 9 04-13-2009 05:12 PM