Reputation: 936
I have a Perl one-liner which will read a file and remove the first field of each line, which are separated by comma and dump the rest.
perl -wan -e 'for (@F) { if (/(aaa),(.*)/) {$text = $2; $text =~ s/$1// ; print "$text\n";}}'
Where aaa is in the first field of each line. This is working fine in Linux, but in Windows it is throwing an error:
Can't find string terminator "'" anywhere before EOF at -e line 1.`
Why is it behaving differently?
Upvotes: 2
Views: 311
Reputation: 50647
You might want to use double instead of single quotes. This might impose problems for quoted text "$text\n"
which can be replaced by perl alternative quoting qq{$text\n}
perl -wane "for (@F) { if (/(aaa),(.*)/) {$text = $2; $text =~ s/$1//; print qq{$text\n}; }}"
Upvotes: 3
Reputation: 241908
In MS Windows, single quotes don't work as in Linux. You have to switch to double quotes.
perl -wan -e "for (@F) { if (/(aaa),(.*)/) {$text = $2; $text =~ s/$1// ; print qq($text\n);}}"
I used qq
for the nested double quotes.
Upvotes: 2