473,815 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Find a text line that starts with forward slash

57 New Member
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 12641
numberwhun
3,509 Recognized Expert Moderator Specialist
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
Perl Beginner
57 New Member
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
75166
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 character? At one time, it was accepted as a truism that Windows (like MS-DOS) was different from Unix because Windows used the backslash as the path separator character, whereas Unix used the forward slash.
6
5726
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). example: <table... border=0> <tr>
2
5386
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 this works if the string is on a single line. If the string goes on more lines (caused by a new line or word wrap), it seems that I need to compute the space between the lines, since the height
2
2542
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 but does not. The KB document explains the missing filters were supposed to be present after applying the service packs but this has not proven true for any of the three XP Pro machines with either SP1 or SP2 we have tested on this week. Does...
2
3413
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 tested these links multiple times, and they always work fine for me. Other links do not seem to have trouble. It seems to be related to "https://" for some reason. I get this for another site too. The statistics page shows the 404 failed link with...
1
15229
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) if you cut and paste a path from windows explorer \\myshare\mydir\mydoc.txt into a form textbox, you can use the following code to transform it into something usable by a browser: mytxt = document.myForm.myTextBox.value; mytxt =...
0
1225
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 asp page and print in another asp page with its original text format . if text area is not good what should i use to get a text line with it's format.
4
4945
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 to protect against goofy characters in the in tags. So I do the following: unsafe_chars = "/#()!@$%^&*{}\'\"`?<>| \t\n" alt_chars = "_________________________" s_artist.translate(maketranstable(unsafe_chars, alt_chars))
8
4061
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 dci/txt file and export it to a separated dci/txt file? Thanks
0
9736
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9226
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7687
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3888
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.