• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

regexp question

Novice question here...
How can I open a file, entirely remove all lines which start w/ 'Path: ' (without the quotes), and write the file to a new filename. I have tried several variations on this code:

#!/usr/bin/perl

open NEWSFILE, "<news_file.txt" or die "Can't open news_file.txt";

open TEMPFILE, ">temp_file.txt" or die "Can't open temp_file.txt";
while (<NEWSFILE>) {
      tr/Path: //;
      print TEMPFILE;
}

close TEMPFILE;
close NEWSFILE;

but no luck.
thanks
0
frenomulax
Asked:
frenomulax
1 Solution
 
jkstillCommented:
simply change these 2 lines:

  tr/Path: //;
  print TEMPFILE;

to:

  print TEMPFILE if ! /Path:/;


That's all it takes.

The /Path:/ says print a line, unless 'Path:' is in the line.

If you want it to only check at the beginning of the line, change it to /^Path:/.

The 'tr' command you used says to translate the characters 'Path:' to nothing, which is exactly what happened, nothing. :)
0
 
frenomulaxAuthor Commented:
Thanks, just what I wanted.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now