Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to capture a line in the text file REF: REF: ID: 27285438

Posted on 2011-09-13
4
321 Views
Last Modified: 2012-05-12
This is a follow up question to this one:
REF: ID: 27285438

In my text file, I have line which starts with #. In the previous code we used to ignore all the line that starts with #. But now, I want to capture a line within the lines that starts with #.

Here is the line I would like to capture:

# Sandbox location : /sandbox/tolgar/something1/somerthing2/something3/

Open in new window


The part that I want to capture is tolgar. and I want to assign it to a variable and return this variable as the others.

Note: something in this line can be as many as we want. But "sandbox location" is the keyword.
And spaces can be more or less. So we need to ignore them.

Thanks,




0
Comment
Question by:Tolgar
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
parparov earned 500 total points
ID: 36530306
Between lines 22 and 23, you can insert the following match:
my $sandbox_location;
if(m|^#\s*Sandbox\s+location\s*\:\s*/sandbox/(.*?)/|) {
   $sandbox_location = $1;
}

Open in new window

afterwards do something with $sandbox_location;
0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36530316
> I want to capture is tolgar. and I want to assign it to a variable and return this variable as the others.
Please post your expect output for this portion.
0
 

Author Comment

by:Tolgar
ID: 36530551
The output that I want is only tolgar assigned to a variable.

Like this:

When I print $login I want to see tolgar.

>>x $login;
>>tolgar

Open in new window

0
 
LVL 9

Expert Comment

by:parparov
ID: 36530696
Between lines 3 and 4 do a
print $sandbox_location, "\n";

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
collecting information 2 180
unable to remove invisible characters with perl 2 89
Perl File::Find alternative 1 78
Matching a random pattern with one common character 2 73
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question