SED Newb - Range Rage!

Hi all

First time poster long time lurker. I've been trying to get my head around SED but I think my beginner status is starting to prove too great a hindrence. I have nearly 100 CSS files that I need to modify in such a way that

label, b, p .text{
some style stuff
}

would become

b ,p .text{
some style stuff
}

label {custom style stuff}

label can appear above in the following ways

label ,...
label, ....
, label...
,label...

What I was trying to do was operate the the different flavours of 'label', and then find the next closing tag '}'. I'm testing the finding of 'label' with

sed 's/,label//g;s/, label//g;;s/label,//g;s/label ,//' test.css
test.css

body{

    color: #000000;
    font-family: Verdana, Arial, Helvetica, Sans-Serif;
    font-size: 10px;
    margin: 0px;
    padding: 0px;
        background:white;
        /*background-image: url(images/background.gif);*/
}

label ,b, p, .text  
{
    color: #000000;
    font-family: Verdana, Arial, Helvetica, Sans-Serif;
    font-size: 10px;
}

label,b, p, .text  
{
    color: #000000;
    font-family: Verdana, Arial, Helvetica, Sans-Serif;
    font-size: 10px;
}

b, p, label .text  
{
    color: #000000;
    font-family: Verdana, Arial, Helvetica, Sans-Serif;
    font-size: 10px;
}

b, p,label .text  
{
    color: #000000;
    font-family: Verdana, Arial, Helvetica, Sans-Serif;
    font-size: 10px;
}

If anyone could give me some direction I'd really appreciate it.

something like this ? :

sed 's|\(.*\)\(label\)\(.*\)|\1\3|g' inputfile.txt

kindly write the output you seek for....

panyam that kind of works on the first step, which is neatly removing label. It does however still leave the comma's. Your code outputs (for example)

,b, p, .text
{
        color: #000000;
        font-family: Verdana, Arial, Helvetica, Sans-Serif;
        font-size: 10px;
}

against the original

label ,b, p, .text
{
        color: #000000;
        font-family: Verdana, Arial, Helvetica, Sans-Serif;
        font-size: 10px;
}

Note how in your output the trailing comma after label (,) still remains - which would of course give incorrect CSS code.

The 2nd part of this PAIN is that after above has ran it would need to be able to find the next closing tag ( } ) and append

label {custom style stuff}

use the below code it will work every time.

sed 's/\,*[ ]label[ ]*\,//g'

Yes it does! Thank you ahmad. Now for the second part of my problem:

Based on the above SED command how can I find the next curly bracket "}" and append some text on the following line ?

easy..

just write this literally :-

sed '
/\}/ a\
"write what ever you want"
something...

' inputfile

note:- don't put any space after a\ .. just press ENTER key.

BR

I dont think this will do what I need. Wont this append to all closing brackets? I just want to append to the next closing bracket after the LABEL SED has ran. Thanks for your help so far.

You can put the line numbers ranges before appending the lines.

ex:
sed '1,8 ....do somthing'

BR

I could, but it wouldn't scale. There would be no gaurentee that the curly brace needle would be within the first 8 lines of the haystack.

Its a toughie!