awk problem - erroring out - unexpected token


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk problem - erroring out - unexpected token
# 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:
# 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:
# 6  
Old 05-09-2014
thanks so much guys. you just saved me hours of pain.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

For loop - unexpected token `do

My requirement is to search for current date-1 .log files in /usr/sas/sas_config/Lev1/SASApp/StoredProcessServer/Logs folder and write the file name to filenames.txt When I ran the script below, I got error as syntax error near unexpected token `do I'm not sure what is wrong in my code. I... (11 Replies)
Discussion started by: Ram Kumar_BE
11 Replies

2. Shell Programming and Scripting

Syntax error near unexpected token

Hi all, I have a simple script that doesn't work somehow. I can't seem to be spotting the cause of the malfunction. count=$((1)) for item in `cat test1.txt` printf %s `sed -n $((count))p test2.txt` > test3.txt count=$((count+1)) do something done I get ; ./why.sh: line 3:... (14 Replies)
Discussion started by: y33t
14 Replies

3. Shell Programming and Scripting

Syntax error near unexpected token `|'

Hi All; I try to write a bash code and I am using command substitution. My code is like: #!/bin/bash IP="10.0.0.1 10.0.0.2" PORT="22 80" USERNAME="admin" SCRIPT_HOST="adminHost" HOME_DIR=/home/admin SCRIPT_DIR=$HOME_DIR/scripts script="sudo /my_remote_script.sh" SSH="/usr/bin/ssh... (7 Replies)
Discussion started by: Meacham12
7 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

5. Homework & Coursework Questions

Syntax error near unexpected token 'else'

1. The problem statement, all variables and given/known data: line 37: syntax error near unexpected token 'else' line 37: ' else' the script is made to take 1 or 2 command line arguments however i get the above stated error when trying to process it. This happens with or without arguments... (6 Replies)
Discussion started by: Ren_kun
6 Replies

6. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies

7. UNIX for Dummies Questions & Answers

Syntax error near unexpected token

hi! just want to seek help on this error: syntax error near unexpected token 'do this is my script # !/bin/sh # for y in 27 25 do exemmlmx -c "ZEEI;" -n XRT$y >> blah done what can be wrong? thanks! (6 Replies)
Discussion started by: engr.jay
6 Replies

8. Shell Programming and Scripting

Unexpected Token Error `;;'

Hello all, Im having an Issue with my script for switch statement , can someone let me know where do i need to correct it. 7 ##******************************************************************************************************* 8 ## ********** FUNCTION USAGE *********** ... (13 Replies)
Discussion started by: raghunsi
13 Replies

9. Shell Programming and Scripting

Syntax error near unexpected token `('

Guys , This is an output of my script errored out for "Syntax error near unexpected token `(' " Can someone tell me whats wrong with my script. Below is my original script pasted. #!/bin/bash Script Creation Date 01/21/2010 Author baraghun ... (7 Replies)
Discussion started by: raghunsi
7 Replies

10. Shell Programming and Scripting

While loop error: Unexpected token done

I have tried to implement a while loop into the code but upon running the following code i am getting the errors: ./Assigntest: line 42: syntax error near unexpected token `done' ./Assigntest: line 42: `done' The code is as follows: #!/bin/bash #Filename: Assignment Author: Luke... (9 Replies)
Discussion started by: warlock129
9 Replies
Login or Register to Ask a Question