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