SED Newb - Range Rage!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SED Newb - Range Rage!
# 1  
Old 06-08-2009
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

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

would become

Code:
b ,p .text{
some style stuff
}

label {custom style stuff}

label can appear above in the following ways

Code:
label ,...

Code:
label, ....

Code:
, label...

Code:
,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

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

Code:
test.css

body{

    color: #000000;
    font-family: Verdana, Arial, Helvetica, Sans-Serif;
    font-size: 10px;
    margin: 0px;
    padding: 0px;
        background:white;
        /*background-image: url(https://www.unix.com/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.
# 2  
Old 06-08-2009
something like this ? :

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

# 3  
Old 06-08-2009
kindly write the output you seek for....
# 4  
Old 06-08-2009
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)

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

against the original

Code:
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

Code:
label {custom style stuff}


Last edited by GoneShootin; 06-08-2009 at 11:33 AM..
# 5  
Old 06-08-2009
use the below code it will work every time.

sed 's/\,*[ ]*label[ ]*\,*//g'
# 6  
Old 06-08-2009
Quote:
Originally Posted by ahmad.diab
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 ?
# 7  
Old 06-08-2009
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



Last edited by ahmad.diab; 06-08-2009 at 11:47 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Using sed to replace a range of number

Trying to use SED to replace numbers that fall into a range but can't seem to get the logic to work and am wondering if SED will do this. I have a file with the following numbers 3 26 20 5. For the numbers that are greater than zero and less than 25, SED would add the word range after the... (7 Replies)
Discussion started by: jimmyf
7 Replies

2. Shell Programming and Scripting

sed/awk date range?

Hi, I am trying to grep out a date range in an access log file. I defined the date like so; DATE1=$(date --date '1 hour ago' '+%m/%d/%y:%H:%M:%S') DATE2=$(date '+%m/%d/%y:%H:%M:%S') Then I just used cat to get the hits to the url into a results.txt; touch /tmp/results.txt cat... (7 Replies)
Discussion started by: Epx998
7 Replies

3. Shell Programming and Scripting

sed delete range

Hi I would like to delete ranges of text from an html file; In the sentence; aqua>Stroomprobleem in Hengelo verholpen <a href="107-01.html"><font color=yellow>107</a> With several sentences like this in that file, where the text between <a href a> varies, so it needs to be deleted in the... (2 Replies)
Discussion started by: mdop
2 Replies

4. Shell Programming and Scripting

how to use sed to get 2nd range?

Hi all, Is there a way to use the sed command to get the second range? For instance: sample.dat: ------------- 11111 22222 33333 44444 ------------- using "sed -n '/^ping/,/^$/p' sample.dat can get the first 2 lines. But is there a way to get the first 4 lines, from... (4 Replies)
Discussion started by: sleepy_11
4 Replies

5. Shell Programming and Scripting

Help a newb with sed?

So here is my problem: I need to do a sed search and replace on the following: variable_blah_STATUS replaced with "replace string". sed 's/variable_blah_STATUS/replace string/g' works great but there is a catch. The catch is that I need to check and not replace variable_blah_STATUS... (3 Replies)
Discussion started by: phreezr
3 Replies

6. Shell Programming and Scripting

sed pattern range

Hi guys, trying to replace a '#' with a ' ' (space) but only between the brackets '(' and ')' N="text1#text2#text3(var1#var2#var3)" N=`echo $N |sed '/(/,/) s/#. //'` echo $N Looking for an output of "text1#text2#text3(var1 var2 var3)" Any ideas? (15 Replies)
Discussion started by: mikepegg
15 Replies

7. UNIX Desktop Questions & Answers

Dual monitor for Intel 82915G & ATI Rage 128 card on FC6, Dell Optiplex Gx520

I want to setup dual monitor for the Dell Optiplex Gx520 computer. The motherboard has an Intel Corporation 82915G Integrated Graphics Controller. Then I add an ATI Rage 128 video card. The dual monitor work on Windows 2000 with the Intel chip as the primary screen and the ATI chip... (0 Replies)
Discussion started by: TsanChung
0 Replies

8. Shell Programming and Scripting

Sed Range command

Hi, I am trying to get all the log entries in a log file based on start and end times, I have tried to use the following but couldnt get the desired output: sed -n '/start/,/end/ p' file & newtime=`echo "$time" | cut -d -start | cut -d" " -start` Kindly help me, Thanks (0 Replies)
Discussion started by: openspark
0 Replies

9. Shell Programming and Scripting

Sed Range Issue

OK, so for a grand overview of what I'm trying to do: I've got 2 files that are mostly like. The file format is: data data data data data data data data data data (2 Replies)
Discussion started by: Wrathe
2 Replies

10. Shell Programming and Scripting

Help needed in sed range pattern

Hi all, I am using sed for extracting the lines that occurs between the 2 patterns using the following command: sed -n '/pattern1/,/pattern2/' filename The above command has no problem and works fine. But I was wondering if there is a way to quit sed when it has extracted the range at... (3 Replies)
Discussion started by: sank
3 Replies
Login or Register to Ask a Question