From your example what distinguishes a block appears to be the first field (ID?), or name of the person. Is that true?
However, your example doesn't match your description:
The line containing "SimpsonM" and "648" is the first in the block.Before Snip --- "SimpsonH","Homer","Simpson","NULL","648","0","218 555","Nuclear Cont +rol","Nuclear Operator","SimpsonM" "SimpsonH","Homer","Simpson","NULL","647","0","218 555","Nuclear Cont +rol","Nuclear Operator","SimpsonM" "SimpsonH","Homer","Simpson","NULL","648","0","218 555","Nuclear Cont +rol","Nuclear Operator","BurnsM" After Snip --- "SimpsonH","Homer","Simpson","NULL","648","0","218 555","Nuclear Cont +rol","Nuclear Operator","SimpsonM"
In any case, consider:
Getting the output sorted to suit is left as an exercise for you.#!/usr/bin/perl use strict; my %output_hash; while(<DATA>) { my ($id_field, @undef) = split /,/, $_; $output_hash{$id_field} = $_; } # Quickie Print print values %output_hash; # Or loop around it if there is more to be done: # foreach my $id_key (sort keys %output_hash) { # the more to be done stuff # print $output_hash{$id_key}; #} __DATA__ "SimpsonH","Homer","Simpson","NULL","648","0","218 555","Nuclear Cont +rol","Nuclear Operator","SimpsonM" "SimpsonH","Homer","Simpson","NULL","647","0","218 555","Nuclear Cont +rol","Nuclear Operator","SimpsonM" "SimpsonH","Homer","Simpson","NULL","648","0","218 555","Nuclear Cont +rol","Nuclear Operator","BurnsM" "SimpsonB","Bart","Simpson","NULL","748","0","218 555","Springfield E +lementary","Student","SimpsonM" "SimpsonB","Bart","Simpson","NULL","748","0","218 555","Springfield E +lementary","Student","SimpsonH" "SimpsonB","Bart","Simpson","NULL","748","1","218 555","Springfield E +lementary","Student","SkinnerP"
Also consider using Text::CSV to manipulate CSV data like the type you've presented as an example.
In reply to Re: Removing multiple lines
by mikeraz
in thread Removing multiple lines
by rycher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |