Re: One-liners: single quotes; altering first line only; printing the changes?
- From: "Peter J. Holzer" <hjp-usenet2@xxxxxx>
- Date: Wed, 20 May 2009 16:54:25 +0200
On 2009-05-20 11:20, Adam Funk <a24061@xxxxxxxxxxxxx> wrote:
perl -pi.bak -e 's!^(<\?xml version=.1\.0. encoding=.)UTF8(.\?\>)!\1UTF-8\2!' *.rdf
It worked, but I have three questions about doing it better.
1. Is there any way to specify single quotes (') in the pattern? (I
realize this is at least as much of a shell problem as a Perl
problem; this is in bash on GNU/Linux.)
\x{27} (or \047 if you prefer to think in octal) should work.
2. Is it possible to tell the command to look at the first line of
each file only? (These were very large files.)
You have to read and copy the whole file to change a line in it - that's
unavoidable. You can only do the substitution on line 1 with something
like
$. == 1 and s!...!...!
I'm not sure if this is much of s speedup.
3. Is it possible to make a perl -i command print to STDOUT the
changes it makes (and only the changed lines)?
I haven't tested it, but the docs say that the output file is
"selected". I take that to mean that STDOUT is unchanged and
print STDOUT "whatever"
should do what you want.
hp
.
- Follow-Ups:
- References:
- Prev by Date: Re: One-liners: single quotes; altering first line only; printing the changes?
- Next by Date: Re: ampersand subroutine
- Previous by thread: Re: One-liners: single quotes; altering first line only; printing the changes?
- Next by thread: Re: One-liners: single quotes; altering first line only; printing the changes?
- Index(es):
Relevant Pages
|