Solved

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

Posted on 2011-09-13
4
323 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
[X]
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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…
Six Sigma Control Plans

696 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