# sed problem



## lhmwzy (Sep 29, 2010)

I have a txt file named test:


```
USER Added by ftpadmin
GENERAL 0,0 120 204800 0
LOGINS 1 0 -1 -1
TIMEFRAME 0 0
FLAGS 3
TAGLINE lanshu4385
DIR /
ADDED 1284812614 ftpadmin
EXPIRES 0
CREDITS 15000
RATIO 0
ALLUP 0 0 0
ALLDN 0 0 0
WKUP 0 0 0
WKDN 0 0 0
DAYUP 0 0 0
DAYDN 0 0 0
MONTHUP 0 0 0
MONTHDN 0 0 0
NUKE 0 0 0
TIME 0 1284812614 0 0
GROUP Teest 0
GROUP eest 0
GROUP dTeest 0
GROUP tTeest 0
GROUP Test 0
IP *@*
```
When I use the following command:


```
#%sed -e '/GROUP/{/Test/! d}' test
sed: 1: "/GROUP/{/Test/! d}
": extra characters at the end of d command
```
also have error.

the system:

```
#uname -a
FreeBSD bxzxfreebsd.slof.com 7.2-RELEASE-p5 FreeBSD 7.2-RELEASE-p5 #1:
Fri Dec  4 17:58:13 CST 2009
[email]lhm@bxzxfreebsd.slof.com[/email]:/usr/obj/usr/src/sys/lhmwzy  amd64
1
```

But this command under linux is OK,how can I do?


----------



## graudeejs (Sep 29, 2010)

try adding *-E* switch before *-e*
also telling what exactly you want to do might help


----------



## lhmwzy (Sep 29, 2010)

killasmurf86 said:
			
		

> try adding *-E* switch before *-e*
> also telling what exactly you want to do might help




```
#sed -E -e '/GROUP/{/Test/! d}' test
sed: 1: "/GROUP/{/Test/! d}
": extra characters at the end of d command
```
NO help.

What I want to do is change


```
USER Added by ftpadmin
GENERAL 0,0 120 204800 0
LOGINS 1 0 -1 -1
TIMEFRAME 0 0
FLAGS 3
TAGLINE lanshu4385
DIR /
ADDED 1284812614 ftpadmin
EXPIRES 0
CREDITS 15000
RATIO 0
ALLUP 0 0 0
ALLDN 0 0 0
WKUP 0 0 0
WKDN 0 0 0
DAYUP 0 0 0
DAYDN 0 0 0
MONTHUP 0 0 0
MONTHDN 0 0 0
NUKE 0 0 0
TIME 0 1284812614 0 0
GROUP Teest 0
GROUP eest 0
GROUP dTeest 0
GROUP tTeest 0
GROUP Test 0
IP *@*
```

to 


```
USER Added by ftpadmin
GENERAL 0,0 120 204800 0
LOGINS 1 0 -1 -1
TIMEFRAME 0 0
FLAGS 3
TAGLINE lanshu4385
DIR /
ADDED 1284812614 ftpadmin
EXPIRES 0
CREDITS 15000
RATIO 0
ALLUP 0 0 0
ALLDN 0 0 0
WKUP 0 0 0
WKDN 0 0 0
DAYUP 0 0 0
DAYDN 0 0 0
MONTHUP 0 0 0
MONTHDN 0 0 0
NUKE 0 0 0
TIME 0 1284812614 0 0
GROUP Test 0
IP *@*
```

Delete all lines start by "GROUP" except "GROUP Test 0"


----------



## lyuts (Sep 29, 2010)

As far as I remember sed is smart enough to recognize several types of delimiters, therefore try to use
`$ sed -E -e '|GROUP|{/Test/! d}' test`


----------



## jasmine (Sep 29, 2010)

Try to add semicolon or newline before terminating function-list {...}, i.e.
`$ sed -e '/GROUP/{/Test/! d[highlight];[/highlight] }' test`


----------



## lhmwzy (Sep 30, 2010)

jasmine said:
			
		

> Try to add semicolon or newline before terminating function-list {...}, i.e.
> `$ sed -e '/GROUP/{/Test/! d[highlight];[/highlight] }' test`



Yes, this works. Thanks!


----------

