tags:

views:

96

answers:

2

Hello everyone:

I am trying to comprehend Perl following the way describe in the book "Minimal Perl".

I've uploaded all source txt files onto my own server : results folder

I got the output from using several bash commands in a "chain" like this:

cat run*.txt | grep '^Bank[[:space:]]Balance'|cut -d ':' -f2 | grep -E '\$[0-9]+'

I know this is far from the most concise and efficient, but at least it works...

As our uni subject now moves onto the Perl part, I'd like to know if there is a way to get the same results in one line?

I am trying something like the following code but stuck in the middle:

Chenxi Mao@chenxi-a6b123bb /cygdrive/c/eMarket/output
$ perl -wlne 'print; if $n=~/^Bank Balance/'
syntax error at -e line 1, near "if $n"
Execution of -e aborted due to compilation errors.
+7  A: 

you shouldn't have a ; after the print. So

perl -wlne 'print $1 if $n=~/^Bank Balance\s*:\s*(\d+)/'
Cine
+3  A: 
perl -F/\:/ -ane 'print $F[1]."\n" if /Bank Balance/ && $F[1]!~/\$-/' run*.txt

also here's a short version of your bash command, using just awk

awk  -F": " '/Bank[ \t]*Balance/&& $2!~/\$-/{print $2}' run*.txt
ghostdog74
@ghostdog74: Thanks for both of your solutions.
Michael Mao