Awk Line 2 Syntax Error At Or Near
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 awk syntax error near line 1 company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions awk syntax error near line 1 awk bailing out 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 near unexpected token (' programmers, just like you, helping each other. Join them; it only takes a minute: Sign up AWK error - syntax error at or near grep up vote 1 down vote favorite I need to create a
Awk Syntax Error At Source Line 1
script to unbind/bind all usb in one linux machine. For this I need to run: lsusb -t wich returns: root@lsdg7sd-fc:~# lsusb -t /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/10p, 12M |__ Port 4: Dev 2, If 0, Class=vend., Driver=ftdi_sio, 12M |__ Port 6: Dev 4, If 0, Class=HID, Driver=usbhid, 1.5M |__ Port 6: Dev 4, If 1, Class=HID, Driver=usbhid, 1.5M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/10p, 480M Now, for this awk syntax error at source line 1 context is example I need to run: // disable the bus 1, port 1 echo '2-4' | tee /sys/bus/usb/drivers/usb/unbind // disable the bus 1, port 2 echo '2-6' | tee /sys/bus/usb/drivers/usb/unbind // enable the bus 1, port 1 echo '2-4' | tee /sys/bus/usb/drivers/usb/bind // enable the bus 1, port 2 echo '2-6' | tee /sys/bus/usb/drivers/usb/bind In order to achieve this by creating a script (I am very new to linux), I did the following: #!/bin/bash lsusb -t | awk '{ bus=""; if($1=="|__") print "Child USB Port: ",$3; else if ($1=="/:") { print $3; var= $(echo $3 | grep -o "[1-9]"); echo $var; } }' var=`echo "02.Port" | grep -o "[1-9]"`; echo $var; var=`echo "02.Port" | grep -o "[0-9]\{2\}"`; echo $var; I tried all the possible combinations in order to set var. I always get an error. awk: line 8: syntax error at or near grep Can anyone suggest a solution or another approach? Thanks for reading. ---------------------- Update Thanks Ed Morton, the input is the result of the command lsusb -t: (at my end) /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/10p, 12M |__ Port 4: Dev 2, If 0, Class=vend., Driver=ftdi_sio, 12M |__ Port 6: Dev 4, If 0, Class=HID, Driver=usbhid, 1.5M |__ Port 6: Dev 4, If 1, Class=HID, Driver=usbhid, 1.5M /: Bus 01.Port 1: Dev 1, Class
Tags Search LQ Wiki Search Tutorials/Articles Search HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie [SOLVED] Need solution for awk: syntax error near line 1 ERROR User Name Remember Me? Password line 2 syntax error near unexpected token newline Linux - Newbie This Linux forum is for members that are new to Linux. Just
Repo Line 2 Syntax Error Near Unexpected Token Newline
starting out and have a question? If it is not in the man pages or the how-to's this is the place! Notices Welcome
Awk: Line 1: Syntax Error At Or Near Print
to LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and http://stackoverflow.com/questions/26739414/awk-error-syntax-error-at-or-near-grep access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here. Having http://www.linuxquestions.org/questions/linux-newbie-8/need-solution-for-awk-syntax-error-near-line-1-error-4175431628/ a problem logging in? Please visit this page to clear all LQ-related cookies. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Search this Thread 10-11-2012, 03:56 AM #1 Vthimmap Member Registered: Oct 2012 Posts: 32 Rep: Need solution for awk: syntax error near line 1 ERROR Using awk in kron shell gives the error awk: syntax error near line 1 awk: bailing out near line 1 Kindly suggest the correct way of using sample script #echo " checks the null value in the first column" less PositPricesUSA.csv.cp | awk -F ',' '$1 == "" { print }' echo "`cat PositPricesUSA.csv.cp | awk -F\, '{print $1}' | sort | uniq -d
Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages http://www.unix.com/shell-programming-and-scripting/247183-awk-problem-erroring-out-unexpected-token.html here. Search Forums Show Threads Show Posts Tag Search Advanced http://superuser.com/questions/687465/awk-does-not-work-correctly-in-my-system Search Unanswered Threads Find All Thanked Posts Go to Page... learn unix and linux commands awk problem - erroring out - unexpected token Shell Programming and Scripting Tags awk, perl, solved Thread Tools Search this Thread Display Modes syntax error #1 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 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; awk syntax error 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 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 2
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 Business Learn more about hiring developers or posting ads with us Super User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question and answer site for computer enthusiasts and power users. 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 does not work correctly in my system [duplicate] up vote 1 down vote favorite This question already has an answer here: sum numbers in different lines in shell 2 answers i cant run this code because of an error awk 'BEGIN {x=0;y=0} { match($13,/([0-9]+)/,a); x = x + a[1]; match($12,/([0-9]+)/,b); y = y + b[1]} END {print "rxPackets:" x " txPackets:" y}' yourfile the problem is ",a" and ",b" that put numbers in array a input is some lines like this: