I\'m looking for a simple way to find the length of the longest line in a file. Ideally, it would be a simple bash shell command instead of a script.
I'm in a Unix environment, and work with gzipped files that are a few GBs in size. I tested the following commands using a 2 GB gzipped file with record length of 2052.
zcat | wc -L and
zcat | awk '{print length}' | sort -u The times were on avarage
117 seconds
109 seconds
Here is my script after about 10 runs.
START=$(date +%s) ## time of start
zcat $1 | wc -L
END=$(date +%s) ## time of end
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"
START=$(date +%s) ## time of start
zcat $1 | awk '{print length}' | sort -u
END=$(date +%s) ## time of end
DIFF=$(( $END - $START ))
echo "It took $DIFF seconds"