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

Hello folks, I am reading from a file and trying to match a few things in there. My file contain the following:

File line Type code D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx~1332222~Note~444912~Implic +it D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx~1666633~Note~966656~Non co +nst D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx~1666673~Note~190994~Old-st +yle D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx~1854547~Note~194417~empty D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx~1877778~Note~916765~Implic +it D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx~1955551~Note~955515~Implic +it

I need to a capture the file and the code belongs to it and send it to a new file the new file should look like this:

D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 444912 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 966656 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 190994 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 194417

I am having problem with the ~ so any ideas or tips, I would appreciate it.

Edited: ~Wed Jul 3 16:52:43 2002 (GMT), by footpad:
Added <code> (and other formatting) tags and corrected minor typos.

Replies are listed 'Best First'.
Re: match from a file and output to another
by flounder99 (Friar) on Jul 03, 2002 at 16:45 UTC
    I think this does what you want.
    use strict; open (INFILE, "<infile") or die "could not open file"; open (OUTFILE, ">outfile") or die "could not open file"; <INFILE>; # dump the header on the first line while (<INFILE>) { print OUTFILE join(" ", (split "~", $_)[0,3]), "\n"; } close INFILE; close OUTFILE;
    outfile will now contain
    D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 444912 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 966656 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 190994 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 194417 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 916765 D:\minibuild\nbsssbs\appl\src\erlmtrihm.cxx 955515
    --UPDATE--

    After thinking about this at lunch. This could be a one liner.

    perl -e '$,=" ";while (<>) {print ((split "~", $_)[0,3],"\n") if (/~/) +}'<infile >outfile
    or even
    perl -aF/~/ -ne '$,=" ";print (@F[0,3],"\n") if /~/' infile >outfile

    --

    flounder