Hi all.
I have some output as follows
How can i capture the text between the two "" so the only output i get is 2M Hotel ?Code:SYSTEM "2M Hotel"
Thanks on advance.
Kind regards.
Hi all.
I have some output as follows
How can i capture the text between the two "" so the only output i get is 2M Hotel ?Code:SYSTEM "2M Hotel"
Thanks on advance.
Kind regards.
I think it works if you pipe your output through
Have funCode:sed s/.*\ \"//|sed s/\"$//
Olle
Another way is to pipe it through awk while setting the Output Field Separator to a double quote (")
-F sets the field separator, $2 is the second columnCode:yourscript | awk -F '"' '{print $2}'
Obviously there are limitations to this method.
Another sed:
Code:#> echo 'SYSTEM "2M Hotel"' | sed "s/.*\"\(.*\)\"/\1/g" 2M Hotel #>
Another sed, which avoid parentheses:
Code:yourscript | sed -e 's/[^"]*"//' -e 's/".*//'
Thanks for all the suggestions guys. Wish i knew what all those characters in the sed commands ment. But it looks a bit exhausting to be honest.
These are "regular expressions" and any programmer worth his salt should know about them.
http://xkcd.com/208/
They are not just for programmers, they're essential also to system administration.
There are lots of sources of material on regular expressions. For sed you can start here:
http://www.gnu.org/software/sed/manu...pressions.html
http://www.faqs.org/docs/abs/HTML/regexp.html
Last edited by Lars Noodén; October 29th, 2011 at 09:26 AM.
Bookmarks