Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syslog text file into database or into .CSV 19 137
Filtering a file to table 9 101
perl script to search for files containing text 3 79
what are these modules in perl script 4 98
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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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