Everybody Linux administrator knows how to use grep command to filter the output of interest.
Unfortunately when grep is used the header line is lost, which sometimes is very useful.
Below is the implementation of hgrep
command that outputs the header as well
# cat hgrep
#!/bin/bash
IFS= read -r header
echo "$header"
grep "$@"
After creating the file allow execution and copy it to /usr/bin/
chmod a+x hgrep
cp hgrep /usr/bin/
Use example:
# ps aux |hgrep ssh
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 548 0.0 0.2 72304 5456 ? Ss Apr21 0:00 /usr/sbin/sshd -D
root 1430 0.0 0.3 107992 7052 ? Ss Apr21 0:00 sshd: root@pts/1
root 1730 0.0 0.3 107992 7024 ? Ss 00:05 0:00 sshd: root@pts/3
root 2132 0.0 0.1 11592 3068 pts/3 S+ 03:14 0:00 /bin/bash /usr/bin/hgrep ssh
You can do a similar implementation for a sort command:
# cat hsort
#!/bin/bash
IFS= read -r header
echo "$header"
sort "$@"