ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nemana, Satya V" <Satya.Nem...@ca.com>
Subject RE: yet another regex question
Date Tue, 14 Dec 2004 19:27:20 GMT
Gilbert, consider using cygwin on windows. Here are the awk and perl
scipts called by bash to do this. I try it in Ant, but I am not yet so
good at it.

Program: splitter.sh
#!/bin/bash
awk '
   BEGIN { flag=0; knt=0; }
      /^bin/  { flag = 1; next; }
      /^mail/ { flag = 2; next; }
      flag == 1 { knt += 1; print knt, $0 ;}
   END { print "Awk found " knt " lines"; }
' < /etc/passwd
perl -e '
$knt=0;
while ( $line = <> ) {
    if ( $line =~ m/^bin/ ) { $flag=1; next; };
    if ( $line =~ m/^mail/ ) { $flag=0; };
    if ( $flag ) { $knt += 1; print "$knt $line"; };
};
print "Perl found $knt lines";
' < /etc/passwd

Results: #./splitter.sh
1 daemon:x:2:2:Daemon:/sbin:/bin/bash
2 lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash
Awk found 2 lines
1 daemon:x:2:2:Daemon:/sbin:/bin/bash
2 lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash
Perl found 2 lines
-Satya

-----Original Message-----
From: RADEMAKERS Tanguy [mailto:Tanguy.RADEMAKERS@swift.com] 
Sent: Tuesday, December 14, 2004 1:20 PM
To: Ant Users List
Subject: RE: yet another regex question

The power of awk and many other goodies:

http://GnuWin32.sourceforge.net/

/t 

>-----Original Message-----
>From: Gilbert Rebhan [mailto:ant@schillbaer.de] 
>Sent: Tuesday, December 14, 2004 6:30 PM
>To: Ant Users List
>Subject: Re: yet another regex question
>
>Hi,
>
>Nemana, Satya V wrote:
>> Gilbert, I wrote an awk script to do this in the past. I 
>need to search
>> for it now. Clue is to add 3 lines in the body of the awk. 
>(line-1) use
>> if statement and set a flag to 1 and "skip 1", if pattern1 
>matches with
>> $0 and then (line-2) reset the flag to 0 and "skip 1", if 
>the pattern2
>> matches with $0. And at the end (line-3) print $0, if the 
>flag is tested
>> with 1. Here flag is an awk variable. Let me know if you 
>still need it
>> and I can get it.
>
>thanks for your friendly offer, but ...
>My env here :
>
>_Windows2000_ / Ant 1.6.2 / j2sdk 1.4.2_06
>
>(optional for regex i have jakarta-oro)
>
>so i'm not able to use the power of awk ...
>
>bye4now, Gilbert
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message