• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

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

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
Tolgar
Asked:
Tolgar
  • 2
1 Solution
 
parparovCommented:
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
 
wesly_chenCommented:
> 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
 
TolgarAuthor Commented:
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
 
parparovCommented:
Between lines 3 and 4 do a
print $sandbox_location, "\n";

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now