escaping square bracket within square bracket
am 29.01.2008 23:44:53 von jois.de.vivre
I have an innumerated list enclosed by square brackets, such as:
[test, test1, test2]
I want to search for an entry in this list (test, test1, or test2).
An entry is always followed by either a comma or a closing bracket, so
want to pattern match for that. Say I'm looking for test1, I would
have a sed command such as:
echo '[test, test1, test2]' | sed s'/.*\(test1[,\]]\).*/\1/'
however, I don't know how to escape the closing square bracket. I
tried googling for this but I don't know exactly how to phrase my
question.
Thanks for any help.
Re: escaping square bracket within square bracket
am 30.01.2008 00:01:12 von Stephane CHAZELAS
On Tue, 29 Jan 2008 14:44:53 -0800 (PST), jois.de.vivre@gmail.com wrote:
> I have an innumerated list enclosed by square brackets, such as:
>
> [test, test1, test2]
>
> I want to search for an entry in this list (test, test1, or test2).
> An entry is always followed by either a comma or a closing bracket, so
> want to pattern match for that. Say I'm looking for test1, I would
> have a sed command such as:
>
> echo '[test, test1, test2]' | sed s'/.*\(test1[,\]]\).*/\1/'
>
> however, I don't know how to escape the closing square bracket. I
> tried googling for this but I don't know exactly how to phrase my
> question.
[...]
Have you tried the sed, regex or regexp man page?
[],]
The "]" must be the first character after the [. \ is not
special within [..]
(you can also do [^],]).
--
Stephane