selecting part of text from output of another command
The following is the output of "grep" command.
grep -R 'table="transaction"' /home/shantanu/*
/hom开发者_如何学Pythone/shantanu/conf/transaction/Transaction.hbm.xml: <class name="com.common.core.transaction.entity.Transaction" table="transaction">
I want to grab the class name from the above line:
com.common.core.transaction.entity.Transaction
It is the first variable in double quotes.
Some variant of this:
grep -R 'table="transaction"' /home/shantanu/* \
| sed 's/.*name="\(.*\)" table.*/\1/'
should get you there. You'll want to adjust the stuff before and after \(.*\)
to be tighter or looser depending on all the data you end having to process.
grep -R 'table="transaction"' /home/shantanu/* | cut -d '"' -f 2
This is a variant of Glenn Jackmans's answer.
$ awk -F\" '/table="transaction"/{print $2}' /home/shantanu/*
It relies strongly on your claim that "It is the first variable in double quotes."
this will work for any order:
<class name="com.common.core.transaction.entity.Transaction" table="transaction">
<class table="transaction" name="com.common.core.transaction.entity.Transaction">
grep -R 'table="transaction"' /home/shantanu/* |\
sed -n 's/.*name="\([^"]*\)".*/\1/;p'
精彩评论