Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I feel silly for asking this, but how do you delete a pattern using tr? I did this in a perl script: Code: system("cat $scrapedFile | tr --delete /M ...
  1. #1
    Just Joined!
    Join Date
    Sep 2008
    Posts
    18

    How to delete a pattern with tr

    Hi, I feel silly for asking this, but how do you delete a pattern using tr?

    I did this in a perl script:
    Code:
    system("cat $scrapedFile | tr --delete /M >$charsRemovedFile");
    Which seems okay, until I just realized it deletes all capital M's, too. I only want it to delete when the specific pattern /M is found. I've tried different ways, but keep failing.

    Thanks,
    James

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    do everything in Perl if you are using Perl.

    Code:
    open( F,"<" ,"file") or die "Cannot read file:$!\n";
    while(my $line = <F>){
      # see perldoc -f tr 
    }

  3. #3
    Just Joined!
    Join Date
    Sep 2008
    Posts
    18
    Thanks, that got me on my way. You've helped my meager perl knowledge go up a step

Posting Permissions

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