New answers tagged wc
printf %d\\n $(wc <file) That will insert a newline between each of printf's arguments, which, when split on a default $IFS are the spaces between wc's output. For example: printf %d\\n $(wc <<< $(seq -s" some splitter $IFS" 100)) 100 298 1975
With shells with support for process substitution (ksh, zsh, bash), you could do something like: read line word byte < <(wc < file) echo "file has $line lines, $word words and $byte bytes" With AT&T ksh or zsh, wc < file | read line word byte should also work.
I like using xargs -n XX to have XX items per line. See: $ wc a 3 5 21 a $ wc < a 3 5 21 $ wc < a | xargs -n 1 3 5 21
You can use tr: wc filename | tr ' ' '\n' , or if you just want the numbers: wc filename | tr ' ' '\n' | head -3
Here is how you can keep counting afer reading the current count: My non-terminating test input source is a ping: $ ping 127.0.0.1 PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.041 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.028 ms 64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.025 ms 64 ...
If you’re willing to specify a time limit (rather than just doing it off the cuff), you could use this trick ( cmdpid=$BASHPID; (sleep 300; kill $cmdpid) & exec ngrep (ngrep args) ) | grep ":80" | wc inspired by this answer to a recent question over on SU; essentially How to stop a running program after 5 minutes and continue?
You can use: $ ngrep -W byline port 80 and dst host 18.104.22.168 | grep ":80" | perl -nle 'system("clear");print $.' perl will keep track what lines you had, clear old output before print it.
Typing Ctrl+C from the terminal sends SIGINT to the foreground process group. If you want wc to survive this event and produce output, you need to have it ignore the signal. The solution is to run wc in a subshell and have its parent shell set SIGINT to be ignored before running wc. wc will inherit this setting and not die when SIGINT is sent to the ...
Top 50 recent answers are included