Sponsored Content
Top Forums Shell Programming and Scripting awk problem - erroring out - unexpected token Post 302900961 by SkySmart on Friday 9th of May 2014 07:22:13 PM
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; }'

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
IO::Scalar(3)						User Contributed Perl Documentation					     IO::Scalar(3)

NAME
IO::Scalar - IO:: interface for reading/writing a scalar SYNOPSIS
Perform I/O on strings, using the basic OO interface... use 5.005; use IO::Scalar; $data = "My message: "; ### Open a handle on a string, and append to it: $SH = new IO::Scalar $data; $SH->print("Hello"); $SH->print(", world! Bye now! "); print "The string is now: ", $data, " "; ### Open a handle on a string, read it line-by-line, then close it: $SH = new IO::Scalar $data; while (defined($_ = $SH->getline)) { print "Got line: $_"; } $SH->close; ### Open a handle on a string, and slurp in all the lines: $SH = new IO::Scalar $data; print "All lines: ", $SH->getlines; ### Get the current position (either of two ways): $pos = $SH->getpos; $offset = $SH->tell; ### Set the current position (either of two ways): $SH->setpos($pos); $SH->seek($offset, 0); ### Open an anonymous temporary scalar: $SH = new IO::Scalar; $SH->print("Hi there!"); print "I printed: ", ${$SH->sref}, " "; ### get at value Don't like OO for your I/O? No problem. Thanks to the magic of an invisible tie(), the following now works out of the box, just as it does with IO::Handle: use 5.005; use IO::Scalar; $data = "My message: "; ### Open a handle on a string, and append to it: $SH = new IO::Scalar $data; print $SH "Hello"; print $SH ", world! Bye now! "; print "The string is now: ", $data, " "; ### Open a handle on a string, read it line-by-line, then close it: $SH = new IO::Scalar $data; while (<$SH>) { print "Got line: $_"; } close $SH; ### Open a handle on a string, and slurp in all the lines: $SH = new IO::Scalar $data; print "All lines: ", <$SH>; ### Get the current position (WARNING: requires 5.6): $offset = tell $SH; ### Set the current position (WARNING: requires 5.6): seek $SH, $offset, 0; ### Open an anonymous temporary scalar: $SH = new IO::Scalar; print $SH "Hi there!"; print "I printed: ", ${$SH->sref}, " "; ### get at value And for you folks with 1.x code out there: the old tie() style still works, though this is unnecessary and deprecated: use IO::Scalar; ### Writing to a scalar... my $s; tie *OUT, 'IO::Scalar', $s; print OUT "line 1 line 2 ", "line 3 "; print "String is now: $s " ### Reading and writing an anonymous scalar... tie *OUT, 'IO::Scalar'; print OUT "line 1 line 2 ", "line 3 "; tied(OUT)->seek(0,0); while (<OUT>) { print "Got line: ", $_; } Stringification works, too! my $SH = new IO::Scalar $data; print $SH "Hello, "; print $SH "world!"; print "I printed: $SH "; DESCRIPTION
This class is part of the IO::Stringy distribution; see IO::Stringy for change log and general information. The IO::Scalar class implements objects which behave just like IO::Handle (or FileHandle) objects, except that you may use them to write to (or read from) scalars. These handles are automatically tiehandle'd (though please see "WARNINGS" for information relevant to your Perl version). Basically, this: my $s; $SH = new IO::Scalar $s; $SH->print("Hel", "lo, "); ### OO style $SH->print("world! "); ### ditto Or this: my $s; $SH = tie *OUT, 'IO::Scalar', $s; print OUT "Hel", "lo, "; ### non-OO style print OUT "world! "; ### ditto Causes $s to be set to: "Hello, world! " PUBLIC INTERFACE
Construction new [ARGS...] Class method. Return a new, unattached scalar handle. If any arguments are given, they're sent to open(). open [SCALARREF] Instance method. Open the scalar handle on a new scalar, pointed to by SCALARREF. If no SCALARREF is given, a "private" scalar is created to hold the file data. Returns the self object on success, undefined on error. opened Instance method. Is the scalar handle opened on something? close Instance method. Disassociate the scalar handle from its underlying scalar. Done automatically on destroy. Input and output flush Instance method. No-op, provided for OO compatibility. getc Instance method. Return the next character, or undef if none remain. getline Instance method. Return the next line, or undef on end of string. Can safely be called in an array context. Currently, lines are delimited by " ". getlines Instance method. Get all remaining lines. It will croak() if accidentally called in a scalar context. print ARGS... Instance method. Print ARGS to the underlying scalar. Warning: this continues to always cause a seek to the end of the string, but if you perform seek()s and tell()s, it is still safer to explicitly seek-to-end before subsequent print()s. read BUF, NBYTES, [OFFSET] Instance method. Read some bytes from the scalar. Returns the number of bytes actually read, 0 on end-of-file, undef on error. write BUF, NBYTES, [OFFSET] Instance method. Write some bytes to the scalar. sysread BUF, LEN, [OFFSET] Instance method. Read some bytes from the scalar. Returns the number of bytes actually read, 0 on end-of-file, undef on error. syswrite BUF, NBYTES, [OFFSET] Instance method. Write some bytes to the scalar. Seeking/telling and other attributes autoflush Instance method. No-op, provided for OO compatibility. binmode Instance method. No-op, provided for OO compatibility. clearerr Instance method. Clear the error and EOF flags. A no-op. eof Instance method. Are we at end of file? seek OFFSET, WHENCE Instance method. Seek to a given position in the stream. sysseek OFFSET, WHENCE Instance method. Identical to "seek OFFSET, WHENCE", q.v. tell Instance method. Return the current position in the stream, as a numeric offset. setpos POS Instance method. Set the current position, using the opaque value returned by "getpos()". getpos Instance method. Return the current position in the string, as an opaque object. sref Instance method. Return a reference to the underlying scalar. WARNINGS
Perl's TIEHANDLE spec was incomplete prior to 5.005_57; it was missing support for "seek()", "tell()", and "eof()". Attempting to use these functions with an IO::Scalar will not work prior to 5.005_57. IO::Scalar will not have the relevant methods invoked; and even worse, this kind of bug can lie dormant for a while. If you turn warnings on (via $^W or "perl -w"), and you see something like this... attempt to seek on unopened filehandle ...then you are probably trying to use one of these functions on an IO::Scalar with an old Perl. The remedy is to simply use the OO version; e.g.: $SH->seek(0,0); ### GOOD: will work on any 5.005 seek($SH,0,0); ### WARNING: will only work on 5.005_57 and beyond VERSION
$Id: Scalar.pm,v 1.6 2005/02/10 21:21:53 dfs Exp $ AUTHORS
Primary Maintainer David F. Skoll (dfs@roaringpenguin.com). Principal author Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com). Other contributors The full set of contributors always includes the folks mentioned in "CHANGE LOG" in IO::Stringy. But just the same, special thanks to the following individuals for their invaluable contributions (if I've forgotten or misspelled your name, please email me!): Andy Glew, for contributing "getc()". Brandon Browning, for suggesting "opened()". David Richter, for finding and fixing the bug in "PRINTF()". Eric L. Brine, for his offset-using read() and write() implementations. Richard Jones, for his patches to massively improve the performance of "getline()" and add "sysread" and "syswrite". B. K. Oxley (binkley), for stringification and inheritance improvements, and sundry good ideas. Doug Wilson, for the IO::Handle inheritance and automatic tie-ing. SEE ALSO
IO::String, which is quite similar but which was designed more-recently and with an IO::Handle-like interface in mind, so you could mix OO- and native-filehandle usage without using tied(). Note: as of version 2.x, these classes all work like their IO::Handle counterparts, so we have comparable functionality to IO::String. perl v5.16.2 2005-02-10 IO::Scalar(3)
All times are GMT -4. The time now is 01:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy