Is there a way to specify multiple spaces as a field delimiter with the cut command (something like a " "+ regex)? For example, what field delimiter I should specify for the following string to reach value 3744?
$ps axu | grep jboss
jboss 2574 0.0 0.0 3744 1092 ? S Aug17 0:00 /bin/sh /usr/java/jboss/bin/run.sh -c example.com -b 0.0.0.0
cut -d' ' is not what I want, because it’s only for a single space. awk is not what I am looking for either, so how to do this with cut?
Actually
awkis exactly the tool you should be looking into:or you can ditch the
grepaltogether sinceawkknows about regular expressions:But if, for some bizarre reason, you really can’t use
awk, there are other simpler things you can do, like collapse all whitespace to a single space first:That
greptrick, by the way, is a neat way to only get thejbossprocesses and not thegrep jbossone (ditto for theawkvariant as well).The
grepprocess will have a literalgrep [j]bossin its process command so will not be caught by thegrepitself, which is looking for the character class[j]followed byboss.This is a nifty way to avoid the
| grep xyz | grep -v grepparadigm that some people use.