Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] How to remove unwanted lines from file.

Expand Messages
  • merlyn@stonehenge.com
    ... Ramesh cat Sourcefile | grep -v ignorestring newfile That s a useless use of cat - grep for that for details. Ramesh mv newfile Sourcefile Ramesh
    Message 1 of 4 , May 10, 2007
    • 0 Attachment
      >>>>> "Ramesh" == Ramesh Polepalli <ramesh.polepalli@...> writes:

      Ramesh> cat Sourcefile | grep -v "ignorestring" > newfile

      That's a "useless use of cat" - grep for that for details.

      Ramesh> mv newfile Sourcefile

      Ramesh> Is there any command line "One liner" available to do the same in Perl
      Ramesh> without having to create new file and renaming it back?

      Yes, it's called "in-place editing", and is described on "perldoc perlrun"
      under the "-i" switch. If you have any questions after reading that
      document, please ask again.

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    • Jenda Krynicky
      From: Ramesh Polepalli ... perl -pi.bak -e $_ = if /ignorestring/ sourcefile ===== Jenda@Krynicky.cz ===
      Message 2 of 4 , May 10, 2007
      • 0 Attachment
        From: "Ramesh Polepalli" <ramesh.polepalli@...>
        > I want to remove some lines containing some specific characters in a
        > file.
        >
        > Is there any command line "One liner" available to do the same in Perl
        > without having to create new file and renaming it back?

        perl -pi.bak -e "$_ = '' if /ignorestring/" sourcefile
        ===== Jenda@... === http://Jenda.Krynicky.cz =====
        When it comes to wine, women and song, wizards are allowed
        to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery
      • merlyn@stonehenge.com
        ... Jenda perl -pi.bak -e $_ = if /ignorestring/ sourcefile I find perl -ni.bak -e print unless /ignorestring/ sourcefile saner to read. Somehow, the
        Message 3 of 4 , May 10, 2007
        • 0 Attachment
          >>>>> "Jenda" == Jenda Krynicky <Jenda@...> writes:

          Jenda> perl -pi.bak -e "$_ = '' if /ignorestring/" sourcefile

          I find

          perl -ni.bak -e 'print unless /ignorestring/" sourcefile

          saner to read. Somehow, the idea of "print ''" seems wasteful,
          and potentially dangerous if "-l" is involved.

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
          See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
        Your message has been successfully submitted and would be delivered to recipients shortly.