terminal - How to keep column headers when using grep? -
Output of some programs starts with the names of columns (e.g., ps a ): < / P>
$ ps a PID TTY STAT time COMMAND 1306 TTY1 SS + 0:00 / sbin / mingetty / dev / TTY1 1318 hvc0 ss + 0:00 / sbin / agetty hvc0 38400 vt100 -Nav 14,696 points / ss0: 00 -bash 15283 points / r + 00:00 ps a Now assume that I have frequencies of agetty Want to find:
$ ps a | | Grep agetty 1318 hvc0 ss + 0:00 / sbin / agetty hvc0 38400 vt100- nav 15,339 points / s + 00:00 grapes agetty I have seen the beginning of ps Unless the output of a , I do not know what is the output of ps? Grep agetty means .
I can print the first line after the matching lines:
$ ps a | Head-N1; Ps a | Grep agetty pid TTY STAT time COMMAND 1318 hvc0 ss + 0:00 / sbin / agetty hvc0 38400 vt100- nav 15542 points / 0s + 00:00 grep agetty However, This does not solve my problem when I do not know how many header lines are there lines to get a header there and the method did not match the lines, or some less workaround is to achieve this goal?
will this help?
ps .. | Awk '/ yourpattern / ||! ^ * S * [0-9] / ' Fill in the yourpattern in place.
You can also ps ... | Awk '/ agett [y] / || ... instead of / agetty / to filter out the awk process itself.
Comments
Post a Comment