I have lines like these, and I want to know how many lines I actually have...
09:16:39 AM all 2.00 0.00 4.00 0.00 0.00 0.00 0.00 0.0
This drop-in portable shell function [ℹ] works like a charm. Just add the following snippet to your .bashrc
file (or the equivalent for your shell environment).
# ---------------------------------------------
# Count lines in a file
#
# @1 = path to file
#
# EXAMPLE USAGE: `count_file_lines $HISTFILE`
# ---------------------------------------------
count_file_lines() {
local subj=$(wc -l $1)
subj="${subj//$1/}"
echo ${subj//[[:space:]]}
}
This should be fully compatible with all POSIX-compliant shells in addition to bash and zsh.