469,330 Members | 1,235 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Find a text line that starts with forward slash

Hi,
Is there a way to find a line in a text file that starts with a forward slash? This is how i find a line in text file that starts with a word and then print that line to another text file:

Expand|Select|Wrap|Line Numbers
  1. open( FILE, "<$file" );
  2. open( COPIED_FILE, ">$copiedfile" );
  3.  
  4. while( <FILE> )
  5. {
  6.    $templine = $_;
  7.    if ($templine =~ m/DELTA\//)
  8.       {print COPIED_FILE "$templine";}
  9. }
  10.  
  11. close FILE;
  12. close COPIED_FILE;
But what if the line I'm trying to find starts with a forward slash...for example /DELTA? The thing is, i won't know everytime what word or number will be after the forward slash...

Thanks,
Terra
Oct 10 '07 #1
2 12202
numberwhun
3,503 Expert Mod 2GB
Hi,
Is there a way to find a line in a text file that starts with a forward slash? This is how i find a line in text file that starts with a word and then print that line to another text file:

Expand|Select|Wrap|Line Numbers
  1. open( FILE, "<$file" );
  2. open( COPIED_FILE, ">$copiedfile" );
  3.  
  4. while( <FILE> )
  5. {
  6.    $templine = $_;
  7.    if ($templine =~ m/DELTA\//)
  8.       {print COPIED_FILE "$templine";}
  9. }
  10.  
  11. close FILE;
  12. close COPIED_FILE;
But what if the line I'm trying to find starts with a forward slash...for example /DELTA? The thing is, i won't know everytime what word or number will be after the forward slash...

Thanks,
Terra
Sure, you could use:

Expand|Select|Wrap|Line Numbers
  1. m/^\//
  2.  
as your pattern match and put whatever you want to match after the \/ (that's backslash, forward slash. The backslash escapes the special meaning of the forward slash, as it does with other special characters inside of a regex.

Regards,

Jeff
Oct 10 '07 #2
Sure, you could use:

Expand|Select|Wrap|Line Numbers
  1. m/^\//
  2.  
as your pattern match and put whatever you want to match after the \/ (that's backslash, forward slash. The backslash escapes the special meaning of the forward slash, as it does with other special characters inside of a regex.

Regards,

Jeff
Thank you so much!! That did it!


Terra
Oct 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Bruce | last post: by
2 posts views Thread by Greg Collins [Microsoft MVP] | last post: by
4 posts views Thread by destroooooy | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.