Re: perl -pi -e for specific line number



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]

.



Relevant Pages

  • Re: perl -pi -e for specific line number
    ... pk schrieb: ... Yes but my problem ist that this command does not modify the input ... thereby making a backup copy). ... if the extension doesn't contain a `*', ...
    (comp.unix.shell)
  • Re: shell script replacing original file
    ... GNU sed does it this way: ... `sed' does this by creating a temporary file and sending output to ... thereby making a backup copy). ... if the extension doesn't contain a `*', ...
    (comp.unix.shell)
  • Re: shell script replacing original file
    ... pk> This option specifies that files are to be edited in-place. ... The extension, if supplied, ... thereby making a backup copy). ... Very similar to the way Perl does it, but for historical reasons, Perl does ...
    (comp.unix.shell)
  • Re: Linking to a .prn file
    ... I was able to modify the registry, and allow MS Access to link ... to .prn files. ... file extension switch locally. ... "John Nurick" wrote: ...
    (microsoft.public.access.externaldata)
  • Re: Maintenance Plan on SQL2005
    ... I denote my backup file name with a convention that tells me what type ... it is and the extension is always .bak. ... One plan for each folder unless you use SP1 then you can delete down one ...
    (microsoft.public.sqlserver.tools)