Awk Syntax Error Unexpected
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the bash syntax error near unexpected token awk company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Awk Syntax Error Near Line 1
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million awk syntax error at source line 1 programmers, just like you, helping each other. Join them; it only takes a minute: Sign up awk: syntax error near unexpected token `(' up vote 2 down vote favorite I tried to assign the output of awk syntax error at source line 1 context is an awk command to a variable: USERS=$(awk '/\/X/ {print $1}' <(w)) This line is part of the following script: #!/bin/sh INTERFACE=$1 # The interface which is brought up or down STATUS=$2 # The new state of the interface case "$STATUS" in up) # $INTERFACE is up if pidof dropbox; then killall dropbox fi USERS=$(awk '/\/X/ {print $1}' <(w)) for user in $USERS; do su -c "DISPLAY=$(awk '/\/X/ {print $11}' <(w)) dropboxd &" $user done
Awk If Syntax Error
;; down) # $INTERFACE is down ;; esac However, I get the following error: script: command substitution: line 14: syntax error near unexpected token `(' script: command substitution: line 14: `awk '/\/X/ {print $1}' <(w))' All brackets are closed. Where is the syntax error? bash awk share|improve this question edited Oct 27 '13 at 11:34 asked Oct 27 '13 at 11:27 orschiro 2,48982549 4 What is this subexpression meant to be: <(w) ? –piokuc Oct 27 '13 at 11:30 "line 14"? It looks like the syntax error may be introduced earlier in your script. –Johnsyweb Oct 27 '13 at 11:31 3 @piokuc: Try cat <(w) to see how <() process substitution works. –Johnsyweb Oct 27 '13 at 11:32 @piokuc When executed in a shell, it shows me the username of the currently logged in user of the running X session: ~ $ awk '/\/X/ {print $1}' <(w) orschiro –orschiro Oct 27 '13 at 11:35 OK, thanks for the explanation. –piokuc Oct 27 '13 at 11:36 add a comment| 1 Answer 1 active oldest votes up vote 5 down vote accepted I'm assuming because you are using #!/bin/sh and not #!/bin/bash that process substitution is not available (or you have a version of bash that doesn't support process subsitiution, pre 4.X.X)
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this awk switch case syntax error site About Us Learn more about Stack Overflow the company Business Learn syntax error unexpected expecting syntaxerror more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Awk: Cmd. Line:1: ^ Unexpected Newline Or End Of String
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up AWK http://stackoverflow.com/questions/19617530/awk-syntax-error-near-unexpected-token syntax error - what's causing it? up vote 3 down vote favorite I have simple bash script: #!/bin/sh column=${1:-1} awk ' {colawk='$column'+2; print $colawk}' awk '(x=4; print $x)' But I have received error: awk: (x=4; print $x) awk: ^ syntax error awk: cmd. line:1: (x=4; print $x) awk: cmd. line:1: ^ unexpected newline or end of string Why? Code in the previous line works. http://stackoverflow.com/questions/8474276/awk-syntax-error-whats-causing-it bash awk share|improve this question edited Dec 13 '11 at 7:49 paxdiablo 488k1179691416 asked Dec 12 '11 at 12:24 user710818 6,4153197163 add a comment| 2 Answers 2 active oldest votes up vote 2 down vote accepted Your problem is with using parentheses instead of braces. Try: awk '{x=4; print $x}' instead, as in the following transcript: pax$ echo a b c d e | awk '(x=4; print $x)' awk: cmd. line:1: (x=4; print $x) awk: cmd. line:1: ^ syntax error awk: cmd. line:2: (x=4; print $x) awk: cmd. line:2: ^ unexpected newline or end of string pax$ echo a b c d e | awk '{x=4; print $x}' d share|improve this answer edited Dec 12 '11 at 12:34 answered Dec 12 '11 at 12:27 paxdiablo 488k1179691416 add a comment| up vote 4 down vote An AWK program is a series of pattern action pairs, written as: condition { action } where condition is typically an expression and action is a series of commands. print is not expression but a statement, so it's a syntax error as expected. share|improve this answer answered Dec 12 '11 at 14:42 kev 70.2k21140185 add
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here. Search Forums Show Threads Show Posts Tag Search Advanced http://www.unix.com/shell-programming-and-scripting/247183-awk-problem-erroring-out-unexpected-token.html Search Unanswered Threads Find All Thanked Posts Go to Page... learn unix https://ask.fedoraproject.org/en/question/27557/syntax-error-near-unexpected-token/ and linux commands awk problem - erroring out - unexpected token Shell Programming and Scripting Tags awk, perl, solved Thread Tools Search this Thread Display Modes #1 05-09-2014 SkySmart Registered User Join Date: Dec 2006 Last Activity: 1 October 2016, 4:12 PM EDT Posts: syntax error 783 Thanks: 586 Thanked 3 Times in 3 Posts 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 awk syntax error 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 Remove advertisements Sponsored Links SkySmart View Public Profile Find all posts by SkySmart #2 05-09-2014 alister Registered User Join Date: Dec 2009 Last Activity: 11 June 2014, 8:40 PM EDT Posts: 3,231 Thanks: 179 Thanked 976 Times in 790 Posts 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 Remove advertisements Sponsored Links alister View Public Profile Find all posts by alister #3 05-09-2014 SkySmart Registered User Join Date: Dec 2006 Last Activity: 1 October 2016, 4:12 PM EDT Posts: 783 Thanks: 586 Thanked 3 Times in 3 Posts 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 reso
`(' bash tcsh asked 2013-07-02 13:40:22 +0000 Roli 3 ●1 ●1 ●3 updated 2013-07-03 10:33:20 +0000 FranciscoD_ 10148 ●55 ●114 ●182 http://ankursinha.in/blog... Hi guys. I wanted to run the "source get_libs" command for the following program named "get_libs" (it's a part of another package and I'm following the instructions from the guide of that package): #*! usr/local/bin/tcsh set file='zlibs.dat' foreach line (`awk '{print $1";"$2}' $file`) set z=`echo $line | awk 'BEGIN {FS=";"} {print $2}'` echo $z "70.,0.30,0.70" | xargs -n 1 | ./get_optic_colors echo $z "70.,0.30,0.70" | xargs -n 1 | ./get_infrared_colors end But when I type source get_libs, I receive this error: bash: get_libs: line 5: syntax error near unexpected token `(' bash: get_libs: line 5: `foreach line (`awk '{print $1";"$2}' $file`)' The information of my system are: Linux User 3.9.7-100.fc17.i686 #1 SMP Fri Jun 21 18:06:22 UTC 2013 i686 i686 i386 GNU/Linux I'm also a bash user. Can you please help me what should I do? Thank you for your help. edit retag flag offensive close merge delete 1 answer Sort by ยป oldest newest most voted 2 answered 2013-07-02 14:44:17 +0000 davidcl 81 ●2 You can not "source" a tcsh script in bash ; to use it just switch to tcsh then "source" this script. $ sudo yum install tcsh $ tcsh $ source get_libs edit flag offensive delete link more CommentsThank you. It worked :)Roli( 2013-07-02 15:25:30 +0000 )edit Your Answer Please start posting anonymously - your entry will be published after you log in or create a new account. Add Answer [hide preview] community wiki (karma is not awarded & many others can edit wiki post) Use your votes! Use the 30 daily voting points that you get! Up-vote well framed questions that provide enough information to enable people provide answers. Thank your helpers by up-voting their comments