Solved

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

Posted on 2011-09-13
4
315 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now