Tag Info

New answers tagged

-1

I ralize its too late, but the OP's command line was almost correct. He just needed the $ in front of his TAB ('\t') grep -o $'\t' infile | wc -l does exaclty what he was after.


1

Strip off the last line from the wc output if there are too few lines for you to want a grand total. word_counts=$(wc -l -- "$@") newline=' ' if [ "$#" -le 9 ]; then word_count=${word_count%"$newline"*} fi printf '%s\n' "$word_count" >>"$1" Note the double quotes in "$@" and around other variable substitutions, without this your script would break ...


2

I don't think you can suppress the total in the multi-argument form. The simplest way I can think of is to stick to the one-argument form, when needed: if [ "$#" -lt 5 ] then for f in "$@"; do wc -l -- "$f"; done >>"$1" else wc -l "$@" >> "$1" fi



Top 50 recent answers are included