sed: remove characters between and including 2 strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed: remove characters between and including 2 strings
# 1  
Old 04-22-2010
sed: remove characters between and including 2 strings

I have the following line:

Code:
4/23/2010 0:00:38.000:  Copying $[19]$[*!20655,,14,+3]3MSYDDC02$[20]

I would like to use sed (or similiar) to remove everthing between and including $[ and ] that appears in the line so it ends up like this.

Code:
4/23/2010 0:00:38.000:  Copying 3MSYDDC02

I have been trying these but i'm really just taking wild guesses now.

Code:
sed -e s/$[.*]//g
sed -e s/\$\[.*\]//g
sed -e s/\$[.*]//g
sed -e s/\$[*]//g
sed -e s/$[*]//g
sed -e s/$[\*]//g
sed -e 's/$[\*]//g'
sed -e 's/$[.*]//g'
sed 's/$[.*]//g'
sed 's/$[*]//g'

Thanks
# 2  
Old 04-22-2010
Code:
$ 
$ cat f4
4/23/2010 0:00:38.000:  Copying $[19]$[*!20655,,14,+3]3MSYDDC02$[20]
$ 
$ perl -pne 's/\$\[.*?\]//g' f4
4/23/2010 0:00:38.000:  Copying 3MSYDDC02
$ 
$

tyler_durden

Using sed:

Code:
$ 
$ cat f4
4/23/2010 0:00:38.000:  Copying $[19]$[*!20655,,14,+3]3MSYDDC02$[20]
$ 
$ sed 's/\$\[[0-9,+*!]*\]//g' f4
4/23/2010 0:00:38.000:  Copying 3MSYDDC02
$


Last edited by durden_tyler; 04-22-2010 at 10:25 PM..
# 3  
Old 04-23-2010
Alternative sed:
Code:
sed 's/$\[[^]]*]//g' infile

# 4  
Old 06-10-2010
I have been trying to utilise the above posts and variations of them on a similiar line without success.

Code:
$[//]9/6/2010 6:00:00 PM: Normal backup using $[1]$[19]VDR_Backups$[20]$[2] (Execution unit 1)$[//30/%D %.1T: %s using $[1]%s$[2]%s]$[/D/30/2010-06-09T18:00:00.000Z+10:00/]$[/T/30/2010-06-09T18:00:00.000Z+10:00/]$[/s/13/Normal backup/]$[/s/29/$[19]VDR_Backups$[20]/]$[/s/62/$[//] (Execution unit 1)$[//20/ (Execution unit %d)]$[/d/1/1/]/]

It doesn't seem to work the same on the last part of this line and the regex appears to be missing the part $[/s/62/$[//] (Execution unit 1)$[//20/ (Execution unit %d)]$[/d/1/1/]/] and the result looks like this:

Code:
9/6/2010 6:00:00 PM: Normal backup using VDR_Backups (Execution unit 1)%s%s]VDR_Backups/] (Execution unit 1)/]

I need it to look like:

Code:
9/6/2010 6:00:00 PM: Normal backup using VDR_Backups (Execution unit 1)

Any ideas?
# 5  
Old 06-10-2010
Maybe something like this ?

Code:
$
$
$ cat f5
$[//]9/6/2010 6:00:00 PM: Normal backup using $[1]$[19]VDR_Backups$[20]$[2] (Execution unit 1)$[//30/%D %.1T: %s using $[1]%s$[2]%s]$[/D/30/2010-06-09T18:00:00.000Z+10:00/]$[/T/30/2010-06-09T18:00:00.000Z+10:00/]$[/s/13/Normal backup/]$[/s/29/$[19]VDR_Backups$[20]/]$[/s/62/$[//] (Execution unit 1)$[
//20/ (Execution unit %d)]$[/d/1/1/]/]
$
$
$ perl -pne 's/\$\[([^\$\]\[])*\]//g; s/\$\[([^\$\]\[])*\]//g' f5
9/6/2010 6:00:00 PM: Normal backup using VDR_Backups (Execution unit 1)
$
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 6  
Old 06-11-2010
Code:
sed -e:o -e's/$\[[^][]*\]//g' -eto

This User Gave Thanks to binlib For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove bracket including text inside with sed

Hello, I could not remove brackets with text contents myfile: Please remove the bracket with text I wish to remove: I tried: sed 's/\//' myfile It gives: Please remove the bracket with text A1 I expect: Please remove the bracket with text Many thanks Boris (2 Replies)
Discussion started by: baris35
2 Replies

2. Shell Programming and Scripting

sed - remove begin of line up to the third and including occurence of character

hello. How to remove all characters in a line from first character ( a $ ) until and including the third occurrence of that character ( $ ). Any help is welcome. (10 Replies)
Discussion started by: jcdole
10 Replies

3. Shell Programming and Scripting

awk or sed script to remove strings

Below am trying to separate FA-7A:1, In output file it should display 7A 1 Command am using Gives same output as below format: 22B7 10000000c9720873 0 22B7 10000000c95d5d8b 0 22BB 10000000c97843a2 0 22BB 10000000c975adbd 0 Not showing FA ports as required format... (5 Replies)
Discussion started by: aix_admin_007
5 Replies

4. Shell Programming and Scripting

Remove the Characters '[' and ']' with Sed

Hi, I am new to Sed and would like to know if it is possible to remove the characters . I have a couple of files with a keyword and would like to remove the substring. I am Using sed s/// but Its not working Thanks for your Support Andrew Borg (2 Replies)
Discussion started by: andrewborg
2 Replies

5. Shell Programming and Scripting

Sed: Remove whitespace between two strings

I have a 13 number string, some whitespace, and then /mp3. I need to join them. Everyline that I need this for begins with "cd" (without the quotes). What it looks like now: cd media/Audio/WAVE/9781933976334 /mp3 What I want my output to be: cd media/Audio/WAVE/9781933976334/mp3 The 13... (7 Replies)
Discussion started by: glev2005
7 Replies

6. Shell Programming and Scripting

Read file and remove special characters or strings

Hello all I am getting data like col1 | col2 | col3 asdafa | asdfasfa | asf*&^sgê 345./ |sdfasd23425^%^&^ | sdfsa23 êsfsfd | sf(* | sdfsasf My requirement is like I have to to read the file and remove all special characters and hex characters ranging form 00-1f from 1st column, remove %"'... (1 Reply)
Discussion started by: vasuarjula
1 Replies

7. Shell Programming and Scripting

Remove strings within range using sed

Hey folks I have a big file that contains junk data between the tags <point> and </point> and I need to delete it (including `<point>' and `</point>'). i.e. a = 1 <point> 123123 2342352 234231 234256 </point> print a needs to become a = 1 print a I'm certain that this is a... (10 Replies)
Discussion started by: ksk
10 Replies

8. Shell Programming and Scripting

remove strings of lowercase characters (with minimum length requirement)

Hi all, I want to delete all lowercase characters from my file, but only strings of length 7 and more. For example, how can I go from: JHGEFigeIGDUIirfyfiyhgfoiyfKJHGuioyrDHG To: JHGEFigeIGDUIKJHGuioyrDHG There should be a trick to add to sed 's///g', but I can't figure it out.... (2 Replies)
Discussion started by: elbuzzo
2 Replies

9. Shell Programming and Scripting

How to use sed to remove html tags including text between them

How to use sed to remove html tags including text between them? Example: User <b> rolvak </b> is stupid. It does not using <b>OOP</b>! and should output: User is stupid. It does not using ! Thank you.. (2 Replies)
Discussion started by: alphagon
2 Replies

10. Shell Programming and Scripting

Using sed with strings of nonprintable characters

Hey, I'm having trouble figuring out the syntax for using sed with string of non-printable characters. What I have is the following format: <field>@@;@@<field>@@;@@...@@;@@<field>@@^@@<field>@@;@@<field>@@;@@...@@;@@<field>@@^@@ ... With the @@;@@ being the delimeters between fields and the... (3 Replies)
Discussion started by: Dickalicious
3 Replies
Login or Register to Ask a Question