On Tue, 3 Feb 2004 11:06:08 -0300 "Marcelo" <[EMAIL PROTECTED]> wrote:
> Hi everyone, need help with two things; > > how do you find out if a line is duplicated in a file, and delete it if so. > > how do you delete a line if it has more than x number of characters. You probably need to define your problem a bit better How large is the file What order is it, and does it have to keep that order Are the duplicate lines sequential or randomly placed perldoc -q duplicates perldoc -f length is initial documentation to read. The simple process for sequential duplicates is open the file for reading open a file for writing read the file line by line test if the line read is the same as the last line read if it is, read the next line, otherwise write the line to file test if the line has more than x characters if it is go to the next line, otherwise write to the file when finished, unlink the initial file then rename your write file to your read file name. here is a simple example, printing to stdout #!/usr/bin/perl -w while (<DATA>){ next if (length($_)>20); next if defined $previous and $previous eq $_; print; $previous = $_; } __DATA__ This is a line This is a line This is a line This is not a line This is a line This is a line This is a line This is a line also -- Owen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>