ok, so this is proving to be kind of difficult even though it should not be.
say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it?
echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal"
If i run the above command, i get back all the other words, which i dont want. all I want returned back is the word "fkafal". Is this possible?
Thanks
try with
grep -o "fkafal"
(or) grep -ow "fkafal"
1 Like
cabrao
December 2, 2010, 10:21am
3
Try:
perl -lne 'print/(fkafal)/'
or
sed -n 's/.*\(fkafal\).*/\1/p'
1 Like
how about in a case like the below:
HOST-RESOURCES-MIB::hrSWRunPath.18121 = STRING: "/usr/local/lib/sa/sadc" ---- HOST-RESOURCES-MIB::hrSWRunPath.18144 = STRING: "/usr/vendor/jdk15/bin/java" ---- HOST-RESOURCES-MIB::hrSWRunPath.20634 = STRING: "/usr/local/bin/ntpd" ---- HOST-RESOURCES-MIB::hrSWRunPath.21659 = STRING: "//usr/sbin/asterisk" ---- HOST-RESOURCES-MIB::hrSWRunPath.29595 = STRING: "/usr/bin/perl"
in the above, the fields are separated by "----".
what if I want to grep out just the field that has the entire string HOST-RESOURCES-MIB::hrSWRunPath.18144 = STRING: "/usr/vendor/jdk15/bin/java in it?
reason why i'm asking is that, the value /usr/vendor/jdk15/bin/java is not always known. what is known is the "HOST-RESOURCES-MIB::hrSWRunPath.18144". So i run into problems trying to grab the entire string associated with that before the ---- delimiter.
you could try ..
grep -o ' H.*18144[^-]*' inputfile
HOST-RESOURCES-MIB::hrSWRunPath.18144 = STRING: "/usr/vendor/jdk15/bin/java" # Only outputs per your previous post
or if not specific try with awk
awk -F "---- " '{print $2}' inputfile # Change $2 to $3 or $1 etc and try