473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 12574
numberwhun
3,509 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

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

Similar topics

30
by: Stephen Ferg | last post by:
I have a question that is not directly Python-related. But I thought I'd ask the most erudite group that I know... :-) When did Windows start accepting the forward slash as a path separator...
6
by: Bruce | last post by:
Hi - I've been looking all over for this and found everything but the variation I need. I have a one-row HTML table with a page title, as text, with a specified font and size (not style). ...
2
by: Zanna | last post by:
Hi all! I'm in difficulty with this: I need to know the height of a text line that is written with Graphics.DrawString(). In theory I need just to get the Graphics.MeasureString() result. But...
2
by: clintonG | last post by:
I only ask this here because it so happens that Windows Search requires filters to enable it to be used to find text in file types such as .aspx, ..cs and so on and is supposed to support doing so...
2
by: Greg Collins [Microsoft MVP] | last post by:
In reviewing my web site statistics, I see that I get 404 errors (often enough to make me ask about it) when users try to click on a link to a secure external site (i.e. an https:// link). I've...
1
by: Kberg | last post by:
In case anyone is interested, this is how I solved the problem of replacing a back slash with a forward slash (as in being able to access a document on a file share on an intranet via a browser) ...
0
by: sajithkahawatta | last post by:
i am new to asp. i want this,it should possible to copy text line from somewhere (like word doc with text format).and paste it on the asp page(in a text area or somewhere). then code to get it from...
4
by: destroooooy | last post by:
Hi folks, I'm finding some (what I consider) curious behavior with the string methods and the forward slash character. I'm writing a program to rename mp3 files based on their id3 tags, and I want...
8
by: Sevla | last post by:
Hello, i need to make a search of a text line on a dci/txt file and after i found it, i´d need to export this line to another new file. could it be possible, copying a specific line of this...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.