Is there any way to specify a field delimiter for more spaces with the cut command? (like " "+) ?
For example: In the following string, I like to reach value '3744', what field delimiter I should say?
$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, for it's only for one single space.
awk
is not what I am looking for either, but how to do with 'cut'?
thanks.
Best Answer
Actually
awk
is exactly the tool you should be looking into:or you can ditch the
grep
altogether sinceawk
knows 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
grep
trick, by the way, is a neat way to only get thejboss
processes and not thegrep jboss
one (ditto for theawk
variant as well).The
grep
process will have a literalgrep [j]boss
in its process command so will not be caught by thegrep
itself, which is looking for the character class[j]
followed byboss
.This is a nifty way to avoid the
| grep xyz | grep -v grep
paradigm that some people use.