Question 1
I can use
grep -o '^[[:alpha:]_]\+[[:blank:]]*([[:blank:]]*)' /etc/rc.d/init.d/functions
to get output like below:
systemctl_redirect ()
checkpid()
__kill_pids_term_kill_checkpids()
__kill_pids_term_kill()
__pids_var_run()
__pids_pidof()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
echo_success()
echo_failure()
echo_passed()
echo_warning()
update_boot_stage()
success()
failure()
passed()
warning()
action()
strstr()
is_ignored_file()
is_true()
is_false()
apply_sysctl()
And I also want to know how many occurrences had been matched, so I use -c
option, this time I only get 26
, can I combine matched contents and counts with grep
built-in options? If not, how to?
Question 2
I found a solution on Github to answer Question 1:
grep -o '^[[:alpha:]_]\+[[:blank:]]*([[:blank:]]*)' /etc/rc.d/init.d/functions \
| tee >(echo -e "\n`wc -l` matched.")
But the output is often weird, which is output after a new shell prompt! Why?
there's no guarantee which process finishes first
true? – liyang Nov 21 '17 at 11:26