in reply to How do I use the switch -l?
An example modified from perlrun, to trim lines in *.txt files to a maximum width of 80 characters ...
perl -lpe 'substr($_, (length $_ > 79) ? 80 : length $_) = ""' *.txt
This code will step through the file, delete all characters beyond the 80 character length of the string and then write the file back out, retaining the original line separator.
Update : Corrected code example to handle lines less than 80 characters in length - Thanks ariels++
|
|---|