Re: perl -pi -e for specific line number
- From: royce <thomas.aregger@xxxxxxxxx>
- Date: Fri, 19 Sep 2008 03:21:41 -0700 (PDT)
pk schrieb:
On Friday 19 September 2008 11:09, royce wrote:
pk schrieb:
On Friday 19 September 2008 10:45, royce wrote:
sed '3{N;s/\n//;}' yourfile
Yes but my problem ist that this command does not modify the input
file but put the new version of the file to the output. And redirect
the output to a tempfile and moving the temp file to the original name
does not work because this is too slow. (see the posts before)
What do you think sed -i and perl -i do?
I think they replace character in the file and don't do the "create
tempfile and move it back" in background. Or am I wrong?
They create a temp file. From "info sed":
`-i[SUFFIX]'
`--in-place[=SUFFIX]'
This option specifies that files are to be edited in-place. GNU
`sed' does this by creating a temporary file and sending output to
this file rather than to the standard output.(1).
This option implies `-s'.
When the end of the file is reached, the temporary file is renamed
to the output file's original name. The extension, if supplied,
is used to modify the name of the old file before renaming the
temporary file, thereby making a backup copy(2)).
This rule is followed: if the extension doesn't contain a `*',
then it is appended to the end of the current filename as a
suffix; if the extension does contain one or more `*' characters,
then _each_ asterisk is replaced with the current filename. This
allows you to add a prefix to the backup file, instead of (or in
addition to) a suffix, or even to place backup copies of the
original files into another directory (provided the directory
already exists).
If no extension is supplied, the original file is overwritten
without making a backup.
This is from perldoc perlrun:
-i[extension]
specifies that files processed by the "<>" construct are to be edited
in-place. It does this by renaming the input file, opening the output file
by the original name, and selecting that output file as the default for
print() statements. [cut, but read it for interesting information]
Ah okay, thank you for these informations.
I implement it now in the same way. Wrote output to tempfile and move
it back.
Thanks
.
- References:
- perl -pi -e for specific line number
- From: royce
- Re: perl -pi -e for specific line number
- From: pk
- Re: perl -pi -e for specific line number
- From: royce
- Re: perl -pi -e for specific line number
- From: pk
- Re: perl -pi -e for specific line number
- From: royce
- Re: perl -pi -e for specific line number
- From: pk
- perl -pi -e for specific line number
- Prev by Date: Re: what's difference between "changed" and "modified"?
- Next by Date: Re: at, cron scheduling error.
- Previous by thread: Re: perl -pi -e for specific line number
- Next by thread: Re: perl -pi -e for specific line number
- Index(es):
Relevant Pages
|