Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    1

    Unanswered: Perl:deleting certain sentences/words in a file

    Is it possible to delete certain sentences or word in a file.Look at the following text below.

    ->begin
    su00106 ka tsatsi la hlano kgwedi
    su00106
    ka
    tsatsi
    la
    hlano
    kgwedi
    su00107 supa tharo lefeela
    su00107
    supa
    tharo
    lefeela
    ->End

    I want to delete those lines with numerics. I mean,the following lines in the text above:

    su00106 ka tsatsi la hlano kgwedi
    su00106

    su00107 supa tharo lefeela
    su00107

    So that i can be left with only the following words in a file"

    ka
    tsatsi
    la
    hlano
    kgwedi
    supa
    tharo
    lefeela


    Is it possible? if yes, please help me with a code

  2. #2
    Join Date
    Jan 2004
    Location
    Germany
    Posts
    167
    I think the module Tie::File will meet your needs:
    Code:
    use Tie::File;
    
    tie @array, 'Tie::File', $file or die $!;
    
    foreach(@array){
      if($_ =~ /\d/){
        $_ = '';
      }
    }
    
    untie @array;
    board.perl-community.de - The German Perl-Community

  3. #3
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    Try

    perl -ni.bak -e "unless (/\d/) {print;}" test.dat

    replacing test.dat by the name of your file.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •