FAQ
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;

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 9 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedFeb 15, '09 at 1:25p
activeFeb 15, '09 at 4:24p
posts9
users3
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase