Sara has asked for the wisdom of the Perl Monks concerning the following question:

Hey guys here is a small problem I want to solve : my file has the following data :
qzang.5 \nbsstools\i95\src\i95val.h@@\main\golden\2 \nbsstools\i95\src\i95val.cxx@@\main\golden\2 \nbsstools\rlp\src\rlpval.cxx@@\main\golden\3 \nbsstools\rlp\src\rlpval.h@@\main\golden\3 source file(s) -- 4 rajeevv.19 \nbsscallpmsg\acl\src@@\main\golden\4 \nbsscallpmsg\acl\src\aclpi.h@@\main\golden\1 \nbsscallpmsg\acl\src\aclpi.cxx@@\main\golden\1 \nbsssbs\appl\src@@\main\golden\4 \nbsssbs\appl\src\radiomeasurements.h@@\main\golden\1
I am want to capture or greps the files with cxx at the end and once I find I wana now in which directory they are so my output should look like this forexample
nbsstools i95val.cxx nbsstools rlpval.cxx nbsscallpmsg aclpi.cxx
I would appricated some hints or tips ;) , thanks

2002-07-05 Edit by Corion Added formatting

Replies are listed 'Best First'.
Re: String Matching
by Abigail-II (Bishop) on Jul 05, 2002 at 16:20 UTC
    #!/usr/bin/perl use strict; use warnings 'all'; my %files; while (<DATA>) { next unless /^\s*\\([^\\]*).*\\(.*\.cxx)\@\@/; push @{$files {$1}} => $2; } foreach my $dir (sort keys %files) { foreach my $file (sort @{$files {$dir}}) { printf "%-15s %s\n" => $dir, $file; } } __DATA__ qzang.5 \nbsstools\i95\src\i95val.h@@\main\golden\2 \nbsstools\i95\src\i95val.cxx@@\main\golden\2 \nbsstools\rlp\src\rlpval.cxx@@\main\golden\3 \nbsstools\rlp\src\rlpval.h@@\main\golden\3 source file(s) -- 4 rajeevv.19 \nbsscallpmsg\acl\src@@\main\golden\4 \nbsscallpmsg\acl\src\aclpi.h@@\main\golden\1 \nbsscallpmsg\acl\src\aclpi.cxx@@\main\golden\1 \nbsssbs\appl\src@@\main\golden\4 \nbsssbs\appl\src\radiomeasurements.h@@\main\golden\1

    Abigail

(jeffa) Re: String Matching
by jeffa (Bishop) on Jul 05, 2002 at 16:32 UTC
    Abigail-II beat me to the punch, but here is a slightly different way for variety:
    use strict; my @thing; # open up the DATA filehandle and loop one line at a time while (<DATA>) { # look for first \ and capture everything until the next \ into $1 # discard everything (.*) but don't be greedy (?) # capture any alphanumeric (\w) that is followed by .cxx into $2 if (/\\([^\\]+).*?(\w+\.cxx)/) { # store $1 and $2 into a datastructure push @thing, [$1,$2]; } } for (@thing) { my ($dir,$file) = @$_; print "$dir\t$file\n"; } __DATA__ qzang.5 \nbsstools\i95\src\i95val.h@@\main\golden\2 \nbsstools\i95\src\i95val.cxx@@\main\golden\2 \nbsstools\rlp\src\rlpval.cxx@@\main\golden\3 \nbsstools\rlp\src\rlpval.h@@\main\golden\3 source file(s) -- 4 rajeevv.19 \nbsscallpmsg\acl\src@@\main\golden\4 \nbsscallpmsg\acl\src\aclpi.h@@\main\golden\1 \nbsscallpmsg\acl\src\aclpi.cxx@@\main\golden\1 \nbsssbs\appl\src@@\main\golden\4 \nbsssbs\appl\src\radiomeasurements.h@@\main\golden\1

    UPDATE per your reply:
    This regex works for the data you provided.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      if(/\\(^\\+).*?(\w+\.cxx)/) I get this error Use of uninitialized value in pattern match (m//) at dirFileSplit.pl line 13.
Re: String Matching
by flounder99 (Friar) on Jul 05, 2002 at 19:48 UTC
    perl -ne 'print "$1\t$2\n" if /\\(\w+).*?(\w+\.cxx)\@\@/' myfile __OUTPUT__ nbsstools i95val.cxx nbsstools rlpval.cxx nbsscallpmsg aclpi.cxx

    --

    flounder