I have a txt file of products that I would like to be able to insert a blank
line whenever the name of the product changes, to make it easier to read. I
found this srcipt hunting about but I don't know how to apply it to the text
file. I've tried all kinds of different things but just don't get it.
example of text file named: products.txt
LAWN SEED 34.00 RED
LAWN SEED1 36.00 BLUE
LAWN SEED1 36.00 BLUE
LAWN SEED1 36.00 BLUE
LAWN SEED2 37.00 PINK
#!/usr/bin/perl -w
my $file = shift @ARGV;
open IN, $file or die "Couldn't open $file: $!";
my $before_line;
while (my $new_line = <IN>) {
print "\n" if ( $before_line and $before_line ne $new_line );
print $new_line;
$before_line = $new_line;
}
close IN;