471,887 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

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 12346
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 YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.