On Wed, Jun 22, 2011 at 01:44:10PM -0700, Warren Michelsen wrote:
> Why does this code as a Unix filter not delete table column 1?
>
> #!/usr/bin/perl
> s/(^<tr>)(<td>.*?<\/td>)(<td>.*?<\/td>)(<td>.*?<\/td>)(<\/tr>)/\1\3\4<\/tr>/;
> print;
>
> Instead, all selected text is replaced with nothing. What about this
> script is malformed?
Your script doesn't read any input. :)
#!/usr/bin/perl -p
s/(^<tr>)(<td>.*?<\/td>)(<td>.*?<\/td>)(<td>.*?<\/td>)(<\/tr>)/$1$3$4<\/tr>/;
Or, if you want to be more verbose:
#!/usr/bin/perl
while (<>) {
s/(^<tr>)(<td>.*?<\/td>)(<td>.*?<\/td>)(<td>.*?<\/td>)(<\/tr>)/$1$3$4<\/tr>/;
print;
}
Note that in Perl you should use $1 rather than \1 in the replacement part
of a substitution.
By the way, you can use a character other than / as the delimiter, to avoid
escaping:
#!/usr/bin/perl -p
s{(^<tr>)(<td>.*?</td>)(<td>.*?</td>)(<td>.*?</td>)(</tr>)}{$1$3$4</tr>};
Ronald
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>