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; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
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.
- Add Line break when first of a line changes Jack Butchie
- Re: Add Line break when first of a line changes Telemachus
- Re: Add Line break when first of a line change... Jack Butchie
- Re: Add Line break when first of a line change... Gunnar Hjalmarsson
- Re: Add Line break when first of a line changes Jack Butchie
- Re: Add Line break when first of a line change... Telemachus
- Re: Add Line break when first of a line change... Gunnar Hjalmarsson
- Re: Add Line break when first of a line ch... Jack Butchie
- Re: Add Line break when first of a lin... Telemachus