|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Add newline to regex
I have a perl script that runs a program and puts the output of the program into a variable. The output of the file looks like: Code:
Statistics 0
AverageTime: [0,0]
Statistics 0
AverageTime: [124,0]I'm trying to run a regular express against this to pull out the first value in each of the parens and put it into an array The expression I have is: Code:
$result = `$program`; @matches = ( $result =~ /AverageTime: \[(.*).\,/g); When I print the arrary: print "@matches\n"; I get all of the requested data, but its all on one line separated with spaces. Code:
0 124 How do I get each match to be its on own in the array? Last edited by Scott; 11-29-2012 at 12:25 PM.. Reason: Code tags, please... |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Hi Boomn4x4, You were near. Here a code that works: Code:
$ cat script.pl
#!/usr/bin/env perl
use warnings;
use strict;
use Data::Dumper;
my $result = <<'EOF';
Statistics 0
AverageTime: [0,0]
Statistics 0
AverageTime: [124,0]
EOF
my @matches = ( $result =~ m/\[(\d+),\d+\]/g );
print Dumper \@matches;
$ perl script.pl
$VAR1 = [
'0',
'124'
]; |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Add a newline after every period | danbroz | Shell Programming and Scripting | 4 | 11-20-2012 04:05 AM |
| How can I add a newline In a text file using Shell Script | kpopfreakghecky | Shell Programming and Scripting | 1 | 08-29-2011 11:12 PM |
| RegEx in Java. \b does not react to a newline | machinogodzilla | Programming | 1 | 05-14-2010 12:35 AM |
| add newline in file after finding specific text | jxh461 | Shell Programming and Scripting | 4 | 07-23-2009 12:31 AM |
| grep and sed to find a pattern and add newline | ssikhar | Shell Programming and Scripting | 5 | 10-26-2004 05:32 PM |
|
|