awk error in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk error in script
# 1  
Old 07-08-2013
awk error in script

Hello Team,

I am using below awk code in the script

Code:
 
ssh -o ConnectTimeout=15 -n -l USER SERVER awk -F'\;' '{ if ( $3 == '-' && $1 ~ /[ES]/ ) print }' *20130706*

but its giving error as

awk: syntax error near line 1
awk: illegal statement near line 1


Please help.

---------- Post updated at 12:26 AM ---------- Previous update was at 12:24 AM ----------

*20130706* file has following data

S;X;36031;
E;-;-;
S;X;-;

So i want to get second and third line as output
# 2  
Old 07-08-2013
Try:
Code:
awk -F'\;' '{ if ( $3 == "-" && $1 ~ /[ES]/ ) print }' *20130706*

# 3  
Old 07-08-2013
i tried the same its giving me same error.

---------- Post updated at 01:40 AM ---------- Previous update was at 01:37 AM ----------

Seems there is some problem with $3 == "-" only as I tried $1 ~ /[ES]/ separately... it workes fine ....
# 4  
Old 07-08-2013
try..

Code:
 
ssh -o ConnectTimeout=15 -n -l USER SERVER "awk -F'\;' '{ if ( \$3 == "-" && \$1 ~ /[ES]/ ) print }' *20130706*"

# 5  
Old 07-08-2013
nopes not working Smilie

---------- Post updated at 02:09 AM ---------- Previous update was at 02:08 AM ----------

thers is some issue in matching hyphen "-" ...
# 6  
Old 07-08-2013
Were you able to execute the awk command alone without the ssh successfully?

Code:
awk -F'\;' '{ if ( $3 == "-" && $1 ~ /[ES]/ ) print }' *20130706*

I was able to execute the above successfully. You may then try the below command.

Code:
ssh -o ConnectTimeout=15 -n -l USER SERVER $(awk -F'\;' '{ if ( $3 == "-" && $1 ~ /[ES]/ ) print }' *20130706*)

# 7  
Old 07-08-2013
There is also a problem with the remote command.
It is evaluated once on the calling system and another time on the remote system.
To solve, put the remote command in 'ticks'. And solve the problem with the embedded ticks.
Code:
ssh -o ConnectTimeout=15 -n -l USER SERVER 'awk -F\; '"'"'{ if ( $3 == "-" && $1 ~ /[ES]/ ) print }'"'"' *20130706*'

That looks ugly.
Better save the normal command in a file "remotecommand.sh"
Code:
#!/bin/sh
awk -F\; '{ if ( $3 == "-" && $1 ~ /[ES]/ ) print }' *20130706*

And send that to the remote server (without -n)
Code:
ssh -o ConnectTimeout=15 -l USER SERVER /bin/sh < remotecommand.sh

The script interpreter (/bin/sh) is called explicitly, and the normal command is piped through the ssh to it.
NB: I replaced the '\;' delimiter by a simple \; meaning a semicolon.

Last edited by MadeInGermany; 07-08-2013 at 05:06 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script with awk command ERROR

Hello im new here... Im trying to read file and create folders from words in it but i get this for loop error awk : line 3 : syntax error at or near for my code is.. #!/bin/bash begin for (( i=1;i<=5;i++)); do awk -v i=$i $0 { print $i } mkdir $i done {print $i} end {} i have... (7 Replies)
Discussion started by: boxstep
7 Replies

2. Shell Programming and Scripting

Calling shell script within awk script throws error

I am getting the following error while passing parameter to a shell script called within awk script. Any idea what's causing this issue and how to ix it ? Thanks sh: -c: line 0: syntax error near unexpected token `newline' sh: -c: line 0: `./billdatecalc.sh ... (10 Replies)
Discussion started by: Sudhakar333
10 Replies

3. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies

4. Shell Programming and Scripting

Help to Iron out Script Awk Error

STRING1=JAVA CONTENTS=$(awk -v x="$STRING1" '$0 ~ x { print ll } { ll = $0}' $LOGFILE | tail -150 | egrep "Jan |Feb |Mar |Apr |May |Jun |Jul |Aug |Sep |Oct |Nov |Dec " | cut -c6-1000 | tail -1) When I run the above from a script, i get the following errors: syntax error at -e line 1,... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

Execution error with awk script

Hi, I run an awk script and I got the error attached below: here are the lines that the compiler point to as an error: duration = timeEnd1-timeBegin1; print "Transmission: type of traffic " flow1 ; print “ - Total transmitted bits = ” totalBits1 ” bits”; print “ - duration = ”... (2 Replies)
Discussion started by: ENG_MOHD
2 Replies

6. Shell Programming and Scripting

awk script Error in Sun Solaris

Hi Friends, the below script has been through the errors in sun solaris. awk '/%s/{f=0 ;n++; print >(file="OUT_" n); close("OUT_" n-1)} f{ print > file}; /%s/{f=1}' $BASE_DIR/concat.TXT awk: syntax error near line 1 awk: bailing out near line 1 And ls $MERGE_DIR/*.R | awk ' { ... (2 Replies)
Discussion started by: krbala1985
2 Replies

7. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

8. Shell Programming and Scripting

awk script error

I am getting this error: awk: cmd. line:1: BEGIN {print "Userid Shell" } awk: cmd. line:1: ^ syntax errorBased on this script: #!/bin/bash awk -F":" \ '{ BEGIN {print "Userid Shell" } loginname=$1 optionalpass=$2 numericuserid=$3 numericgroupid=$4 username=$5 userhomedir=$6... (1 Reply)
Discussion started by: holocene
1 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

10. Shell Programming and Scripting

error in awk script

could any one tell me the error in the script here... it says awk: syntax error near line 15 awk: bailing out near line 15 ... the awk script is attached #This awk script collects the undec neighbour info # BEGIN { printf "SOURCE\tSECTOR\tPNPHASE\tLEVEL\t\REFERENCE\n" } ... (7 Replies)
Discussion started by: rraajjiibb
7 Replies
Login or Register to Ask a Question