473,241 Members | 1,682 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,241 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 12567
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

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.