How to truncate STDIN line length?
问题 I've been parsing through some log files and I've found that some of the lines are too long to display on one line so Terminal.app kindly wraps them onto the next line. However, I've been looking for a way to truncate a line after a certain number of characters so that Terminal doesn't wrap, making it much easier to spot patterns. I wrote a small Perl script to do this: #!/usr/bin/perl die("need max length\n") unless $#ARGV == 0; while (<STDIN>) { $_ = substr($_, 0, $ARGV[0]); chomp($_);