Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] sed and ANSI sequences



On Tue, Oct 18, 2011 at 02:04:38PM -0400, David Kramer wrote:
> Thanks for all your help.  The only real problem I'm having at this
> point is matching square brackets.  Since square brackets need to be
> escaped even when maching a set of characters, I don't know how to tell
> it to match an open square bracket then characters in a set, then a
> close square bracket.
> 
> This is what I mean: Lets say I want to match [ followed by lower case
> letters or a period, followed by ].
> MATCH:  [net.thekramers.foo]
> NOT A MATCH:  net.thekramers.foo
> NOT A MATCH:  [net.thekramers.Foo!]

You can use a character class that just contains the bracket, e.g.:

$ cat junk.txt
blah [foo.derek.bar] blah nada
blah [foo.derek.bar!] blah nada
blah foo.derek.bar blah nada
$ grep '[[][a-z.]\+[]]' junk.txt 
blah [foo.derek.bar] blah nada
$ sed 's/[[][a-z.]\+[]]/[address redacted]/g' junk.txt
blah [address redacted] blah nada
blah [foo.derek.bar!] blah nada
blah foo.derek.bar blah nada


-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.




Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org