Awk Print Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Awk Syntax Error Near Unexpected Token ('
and policies of this site About Us Learn more about Stack awk syntax error near line 1 Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Awk Syntax Error At Source Line 1
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; awk syntax error at source line 1 context is it only takes a minute: Sign up AWK (unexpected newline or end of string) up vote 0 down vote favorite I'm trying to execute bash script but I'm got stuck. data $ cat test.txt cat,command,for cp,command,for ls,command,to script #!/bin/bash CUT_FILE=test.txt TRN_GUID="1bcd1adf-2016-443b-9f00-2e4ce20726d7" LCTN_ID="8002" LCTN_NAME="TEST FILE" LCTN_ADDR1="This is test" cat $CUT_FILE | awk -F ',' '{ print '$TRN_GUID','$LCTN_ID','$LCTN_NAME','$LCTN_ADDR1',$1,$2 }' output -bash-3.2# sh awk if syntax error test4 awk: cmd. line:1: { print 1bcd1adf-2016-443b-9f00-2e4ce20726d7,8002,TEST awk: cmd. line:1: ^ unexpected newline or end of string desired output 1bcd1adf-2016-443b-9f00-2e4ce20726d7,8002,"TEST FILE","This is test",cat,command Any ideas? shell awk share|improve this question edited Jun 28 '15 at 9:32 ShellFish 3,1891926 asked Jun 28 '15 at 8:10 akhilesh chand 8219 learn to use set -vx from your command line and then examine the lines preceded with +. These lines are where variables have expanded to their values. You should see (with a little thought), where things are breaking .Good luck. –shellter Jun 28 '15 at 10:59 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted Syntax Error You are closing your script using the single quotes. awk -F ',' '{ print '$TRN_GUID','$LCTN_ID','$LCTN_NAME','$LCTN_ADDR1',$1,$2 }' Can you see, using the syntax highlighting, that the script gets closed after print '? You should use double quotation marks inside your script to prevent this, like so: awk -F ',' '{ print "$TRN_GUID", "$LCTN_ID", "$LCTN_NAME", "$LCTN_ADDR1", $1, $2 }' Do you notice the difference in syntax hi
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
Awk Switch Case Syntax Error
more about Stack Overflow the company Business Learn more about hiring developers or posting awk print column ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community
Awk Print Delimiter
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 syntax error: awk: line 29: syntax error at or http://stackoverflow.com/questions/31097457/awk-unexpected-newline-or-end-of-string near : up vote 1 down vote favorite I have written a awk script and I keep on getting the following error: awk: line 29: syntax error at or near : I do not understand why I keep on getting this error. The script is below(script is large but the error is only at the top section. Just added the script for completeness. A flag has been marked for http://stackoverflow.com/questions/14779671/awk-syntax-error-awk-line-29-syntax-error-at-or-near the line a error). #!/bin/sh tshark -V -r $1 > .pcap_out1_ver.txt tshark -r $1 > .pcap_out_summ.txt awk -F ":" ' BEGIN { #Packet types and subtypes. frame_id[0] = "Association Request"; frame_id[1] = "Association Response"; frame_id[2] = "Association Response"; frame_id[3] = "Reassociation Response"; frame_id[4] = "Probe Request"; frame_id[5] = "Probe Response"; frame_id[6] = "Reserved"; frame_id[7] = "Reserved"; frame_id[8] = "Beacon"; frame_id[9] = "ATIM"; frame_id[10] = "Disassociation"; frame_id[11] = "Authentication"; frame_id[12] = "Deauthentication"; frame_id[13] = "Action"; for(x=14; x<24; ++x) { frame_id[x] = "Reserved"; } frame_id[24] = "Block Ack Request"; frame_id[25] = "Block Ack"; frame_id[26] = "PS-Poll"; frame_id[27] = "RTS"; #******Error here**** frame_id[28] = "CTS"; frame_id[29] = "ACK"; frame_id[30] = "CF-end"; frame_id[31] = "CF-end + CF-ack"; frame_id[32] = "Data"; frame_id[33] = "Data + CF-ack"; frame_id[34] = "Data + CF-poll"; frame_id[35] = "Data + CF-ack +CF-poll"; frame_id[36] = "Null"; frame_id[37] = "CF-ack"; frame_id[38] = "CF-poll"; frame_id[39] = "CF-ack + CF-poll"; frame_id[40] = "QoS data"; frame_id[41] = "QoS data + CF-ack"; frame_id[42] = "QoS data + CF-poll"; frame_id[43] = "QoS data + CF-ack + CF-poll"; frame_id[44] = "QoS Null"; frame_id[45] = "Reserved"; frame_id[46] = "QoS + CF-poll (no data)"; frame_id[47] = "Qos + CF-ack (no data)"; packet_type[0] = "Management"; packet_type[1] = "Control"; packet_type[2] = "Data"; #Variables for stori
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 company http://unix.stackexchange.com/questions/199236/awk-is-throwing-an-error-unexpected-newline-or-end-of-string Business Learn more about hiring developers or posting ads with us Unix & Linux Questions https://en.wikibooks.org/wiki/AWK Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top AWK syntax error is throwing an error “unexpected newline or end of string” up vote 0 down vote favorite My Bash script: declare -a lang=('english' 'spainsh') sms="Free msg: Due to upgrades on apps you’ll need a new version by yyyy/mm/dd to app running. Visit a store or go to" url="google.com/UA2392 to upgrade your app." awk '{print $1 "," '${servicegrade[0]}' "," '${lang[1]}' ",,," '$sms' "," '$url'}' inputfile.csv > inputfile.txt ERROR: awk: cmd. line:1: {print $1 "," 267 "," en ",,," awk syntax error Free awk: cmd. line:1: ^ unexpected newline or end of string bash awk share|improve this question edited Apr 28 '15 at 21:37 PersianGulf 4,50422549 asked Apr 28 '15 at 21:34 user_tmo 1617 You have some problem: 1. you have to import your array into awk, , 2. if you question , please put your text file into your question. –PersianGulf Apr 28 '15 at 21:43 You can import your shell variable via -v : stackoverflow.com/questions/7194100/… –PersianGulf Apr 28 '15 at 21:44 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted The problem you are seeing is directly related to the way that you are quoting (or more accurately, not quoting) your awk command line and the interpolated shell variables. (Both for the shell and for awk.) You have this: awk '{print $1 "," '${servicegrade[0]}' "," '${lang[1]}' ",,," '$sms' "," '$url'}' inputfile.csv > inputfile.txt Empirically I can see from the error message that servicegrade=267, lang=en, sms=Free msg:..., but url is not visible (that's ok) so we'll assume url=http://example.net. The important part is to look at your quotes on the commnd line. Anything inside the 'single quotes' is treated as a single command line. If you abut a single quote against a double quote you're also ok (echo 'hello'"world" has a single argument). But as soon as y
about awk, see An Awk Primer. Contents 1 Versions 2 Introduction 3 Some basics 4 Some examples 5 Regular expressions 6 Booleans 7 Start and End 8 Begin and End 9 Variables 10 Arrays 11 Punctuation 12 Grand example 13 Options 14 Oneliner examples 15 See also 16 Books 17 External links Versions[edit] There are three major versions of awk: awk or Bell Labs awk nawk or new awk gawk (GNU awk) Both nawk and gawk will run awk programs without modification. Introduction[edit] Awk reads from a file or from its standard input, and outputs to its standard output. You will generally want to redirect that into a file, but that is not done in these examples just because it takes up space. awk does not get along with non-text files, like executables and FrameMaker files. If you need to edit those, use a binary editor like hexl-mode in emacs. A frustrating thing about trying to learn awk is getting your program past the shell's parser. The proper way is to use single quotes around the program, like so: >awk '{print $0}' filename The single quotes protect almost everything from the shell. In csh or tcsh, you still have to watch out for exclamation marks, but other than that, you're safe. Another frustrating thing about trying to learn awk is the lovely error messages: awk '{print $0,}' filename awk: syntax error near line 1 awk: illegal statement near line 1 gawk generally has better error messages. At least it tells you where in the line something went wrong: gawk '{print $0,}' filename gawk: cmd. line:1: {print $0,} gawk: cmd. line:1: ^ parse error So, if you're having problems getting awk syntax correct, switch to gawk for a while. Some basics[edit] Awk recognizes the concepts of "file", "record", and "field". A file consists of records, which by default are the lines of the file. One line becomes one record. Awk operates on one record at a time. A record consists of fields, which by default are separated by any number of spaces or tabs. Field number 1 is accessed with $1, field 2 with $2, and so forth. $0 refers to the whole record. Some examples[edit] Perhaps the quickest way of learning awk is to look at some sample programs. The one above will print the file in its entirety, just like cat(1). Here are some others, along with a quick description of what they do. >awk '{print $2,$1}' filename will print the second fi