March 20th, 2006, 10:18 AM
Using awk !!!
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 ?
March 20th, 2006, 02:37 PM
perl , something like
perl -pe 's/\[(.+)\]/$1/;'
March 20th, 2006, 03:35 PM
Thanx, penguin but I'd like to know how to do it in shell.
March 20th, 2006, 06:14 PM
You can use sed to strip off everything up to and including the '[', and everything from the ']' to the end of line:
I think using ';' to separate two sed commands is undocumented - to be on the safe side you could put them on separate lines:
$ echo 'eserver xSeries 335 -[abcdefgh]-' | sed 's/.*\[//;s/\].*//'
$ echo 'eserver xSeries 335 -[abcdefgh]-' | sed 's/.*\[//
March 21st, 2006, 01:21 AM
You could also use two -e statements You can build up a multiline script like that
Originally Posted by DevCoach
March 22nd, 2006, 07:58 AM
Thanx you very much for this solution