You were close. Sed's pattern matching is greedy though, so the regex
Code:
s/\[.*\]//g
will match everything from the first opening bracket to the last closing one. What you need is to replace the '.' (which means 'any character'), with 'not closing bracket', that is [^]]:
Code:
sed 's/\[[^]]*\]//g'
should do the trick
In fact the last closing bracket does not need to be escaped, it will already be taken as litteral :
Code:
... sed 's/\[[^]]*]//g'
---------- Post updated at 04:05 PM ---------- Previous update was at 03:56 PM ----------
The right expression to do it one shot is :
Code:
... sed 's/[[(][^])]*[])]//g'
Code:
$ echo 'this (is) a [test]!!!'
this (is) a [test]!!!
$ echo 'this (is) a [test]!!!' | sed 's/[[(][^])]*[])]//g'this a !!!
Note that this one shot notation will also match the [...) and (...] blocks :
Code:
$ echo 'this (is) a [darn) funny (and] crazy [test]!!!'
this (is) a [darn) funny (and] crazy [test]!!!
$ echo 'this (is) a [darn) funny (and] crazy [test]!!!' | sed 's/[[(][^])]*[])]//g'this a funny crazy !!!
Hi everyone,
I need to replace the text between two strings (html tags) and I'm having trouble figuring out how to do so. I can display the text with sed but I'm not having any luck deleting the text between the two strings.
My file looks like this:
<oths>test</oths><div class="text">1928... (2 Replies)
Dear all,
I have a variable called $abc, which the value is something like below,
*** *********** : *****
where * can be anything. I need to remove all but the final characters until last whitespace.
example
grd groupstudy : tutor6/7
becomes tutor6/7
something like
if... (2 Replies)
i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings...
for example the awk code removing consecutive identical word is:... (2 Replies)
i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings...
for example the awk code removing consecutive identical word is:... (2 Replies)
So, I've been working on a project which takes layer 7 metadata from pcap dumps and archives it. However, there is a lot of dataless information that I don't want in my output. I know of ways to produce the output I want from the input file below, but I want a method of doing this, regardless of... (2 Replies)
I have file that looks like:
ATOM 2517 O VAL 160 8.337 12.679 -2.487
ATOM 2518 OXT VAL 160 7.646 12.461 -0.386
TER
ATOM 2519 N VAL 161 -14.431 5.789 -25.371
ATOM 2520 H1 VAL 161 -15.336 5.698 -25.811
ATOM 2521 H2 VAL 161 -13.416 10.529 17.708
ATOM 2522 H3 VAL 161 -14.363 ... (4 Replies)
I am passing a list of strings $list and want to remove all entries with --shift=number, --sort=number/number/..., --group=number/number/... Also are removed whether upper or lower case letters are used
For example the following will all be deleted from the list
--shift=12
--shift=2324... (7 Replies)