in reply to Delete strings

You can't delete lines from a file. You can copy a file while doing modifications to what is copied. So after opening the two files,

  1. While the source hasn't been exhausted,
    1. Read a line from the source.
    2. If line contains '1.0' or such a line was already found,
      1. Print the line to the destination.

As a one-liner:

perl -ne"print if $f ||= /1\.0/" infile >outfile

or in-place:

perl -i.bak -ne"print if $f ||= /1\.0/" file

Update: The above were for the Windows Command shell. Below are adaptations for bash:

perl -ne'print if $f ||= /1\.0/' infile >outfile

or in-place:

perl -i~ -ne'print if $f ||= /1\.0/' file

Replies are listed 'Best First'.
Re^2: Delete strings
by vinoth.ree (Monsignor) on Apr 10, 2009 at 08:51 UTC

    Your code is not working for me!

    Vinoth,G

      Are you on Unix or on Windows? On Unix, the shell would interpolate $f in double quoted strings, so it's usually easier to use single quotes for Perl one-liners...  OTOH, on Windows you'd have to use double quotes, as single quotes don't work (as quotes) with the standard shell...

        I am on Unix, Now I understand it. Thanks

        Vinoth,G

      Try executing as below

      perl -i.bak -ne"print if "\$f" ||= /1\.0/" file

      In unix the shell interprets the $f. So you were unable to execute.

      --Lakshmanan G.

      The great pleasure in my life is doing what people say you cannot do.


      ree: your reply is not an error message for me.

      Update: identified node to which this is a response.