You didn't tell us your purpose, so it's hard to say. But the error boils down to this: You can use either single or double quotes around an argument in the shell (bash, in this case), and either type can quote the other, but just as in Perl, there is no interpolation or escaping within single quotes. So:

echo "'$SHELL'" -> outputs 'bash' echo '"$SHELL"' -> outputs "$SHELL"

So if you need to include both kinds of quotes in a command line's arguments, you have a couple of choices: One is to use double quotes around the arguments and escape any double quotes within them. The problem with that is that you'll also need to escape other shell meta characters like ! and (), and that can lead to a complicated mess of backslashes. The other option is to switch back and forth between quote types as needed. You can do this in shell:

echo "a ' quote"' and a " quote' outputs: a ' quote and a " quote

So you can do your pipeline something like this, using single quotes around most of it but switching to double quotes around your literal single quotes:

cat file.txt | perl -ne '{chomp; ($a, $b) = split/\s+/; $s = "$a $b"; + next if($s !~ /^\w+\'"'"'?\w+?\s+\w+\'"'"'?\w+?$/); print "$_\n"}' | + wc -l

Aaron B.
Available for small or large Perl jobs; see my home node.


In reply to Re^3: syntax error near unexpected token `)' by aaron_baugher
in thread syntax error near unexpected token `)' by vit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.