nmattam
September 28, 2009, 5:15am
1
Hello experts,
I have a file containing the following text(shortened here).
File Begin
-----[31-32 changed to 31-32]-----
< # Billboard.d3fc1302a677.imagePath=S:\\efcm_T4
< Billboard.d3fc1302a677.imagePath=S:\\efcm_T4
---
> # Billboard.d3fc1302a677.imagePath=S:\\efcm_Cassini
> Billboard.d3fc1302a677.imagePath=S:\\efcm_Cassini
-----[after 248 inserted 249-266]-----
>
> # ShowDialogAction.4aa6f5a0a2a1.buttonLabel=OK
> ShowDialogAction.4aa6f5a0a2a1.buttonLabel=OK
>
> # ShowDialogAction.4aa6f5a0a2a1.cancelButtonLabel=Cancel
> ShowDialogAction.4aa6f5a0a2a1.cancelButtonLabel=Cancel
>
File End
I now need to write a perl script to grep for the header containing 'changed' (here : -----[31-32 changed to 31-32]-----),
and count all the lines only having '>' symbol.
For example: Here i grep for the word 'changed' from the first header and count the lines containing '>'. So the count must be 2.
Similarly for the second match 'inserted', the number of lines will result in 7 with '>' symbol.
Please help me....Thanks in advance.
local $/="\n\n";
open FH,"<yourfile.txt";
while(<FH>){
if(/inserted/){
my $cnt=()=$_=~/(>)/g;
print $cnt,"\n";
}
}
nmattam
September 28, 2009, 6:17am
3
Thanks cherry for a quick response!!! I actually am trying this:
#!/usr/bin/perl
use Shell;
open THEFILE, "C:\galileo_integration.txt" || die "Couldnt open the file!";
@wholeThing = <THEFILE>;
close THEFILE;
foreach $line (@wholeThing){
if ($line =~ m/\\0$/){
@nextThing = $line;
if ($line =~ s/\\0/\\LATEST/g){
@otherThing = $line;
@grep_results = qx{cleartool diff -ser @nextThing @otherThing};
print "@grep_results\n";
$inserted = grep( "inserted" | "/^>$/" | "wc-l", @grep_results);
print "Number of lines Inserted, $inserted\n";
$deleted = grep( "deleted" | "/^>/" | "wc-l", @grep_results);
print "Number of lines Deleted, $deleted\n";
$changed = grep( "changed" | "/^>/" | "wc-l", @grep_results);
print "Number of lines Changed, $changed\n";
}
}
}
Output it gives is:
Number of lines Inserted, 100
Number of lines Deleted, 100
Number of lines Changed, 100
All gives me the same wordcount, but i want to grep line count based on matching Inserted, Deleted, Changed.
Number of lines Inserted, 100
Number of lines Deleted, 60
Number of lines Changed, 20
Appreciate your help!!!!