Hello I have a line like this
Product Name: eserver xSeries 336 -[abcdefgh]-
I'd like to get the string abcdefgh in shell using sed, awk or whatever else fits
I tryed awk /\[/,/\]/p but it doesn't work. I tryed many things but awk or sed without any success.
Any advice on how to do it ?
perl :), something like
perl -pe 's/\[(.+)\]/$1/;'
Thanx, penguin but I'd like to know how to do it in shell.
You can use sed to strip off everything up to and including the '[', and everything from the ']' to the end of line:
$ echo 'eserver xSeries 335 -[abcdefgh]-' | sed 's/.*\[//;s/\].*//'
abcdefgh
I think using ';' to separate two sed commands is undocumented - to be on the safe side you could put them on separate lines: