Reputation: 416
I'm trying to make the output of a ps -ef
more readable on Red Hat Linux. I know this has been asked many times, but I've several java processes that I regulary need to monitor and the line length for each process is atleast 500 characters but each line is a different length. I need the 1st 14 characters so I get the pid and around the last 40 characters of the same line to get the name.
What I've got so far is:
ps -ef | grep -v 'eclipse' | grep java | cut -c1-14
which strips out my copies of Eclipse that are running and then gets the other java processes and then cuts in the 1st part of the line.
I know how to get the last part by using rev
both sides of the cut, but I can't work out how to combine the 2 together.
Upvotes: 0
Views: 82
Reputation: 328594
You can give cut
several regions to cut but it can't cut from the end, so to cut the last 40 characters, you need to know the line length in advance.
I suggest to use a more powerful tool like gawk
:
ps -ef|gawk '
/eclipse/ {next}
/java/ {
printf("%-10s %8s ...%s\n", $1, $2, substr($0,length()-40));
}'
which also allows you to format the output nicely.
Upvotes: 1