Replace space, that is not in html tags <> with new line using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace space, that is not in html tags <> with new line using sed
# 1  
Old 07-27-2008
Replace space, that is not in html tags <> with new line using sed

Hi, I am working on transforming html code text into the .vert text format. I want to use linux utility sed. I have this regexp which should do the work: s/ \(?![^<>]*>\)/\n/g. I use it like this with sed: echo "you <we try> there" | sed 's/ \(?![^<>]*>\)/\n/g' ... The demanded output should be:
you
<we try>
there
But I get the same string as on input. Is the regexp wrong? Or am I using sed incorrectly? Thanks for your help.
# 2  
Old 07-27-2008
Try:

Code:
sed 's/ /\n/g'

Regards

Last edited by Franklin52; 07-27-2008 at 06:51 PM.. Reason: forgot the s
# 3  
Old 07-27-2008
Franklin - that will split <we try> into
Code:
<we 
try>

# 4  
Old 07-27-2008
Quote:
Originally Posted by jim mcnamara
Franklin - that will split <we try> into
Code:
<we 
try>

That's my problem, I need space characters in html tags not to be replaced by \n. Only if spaces not in '<' and '>'.
# 5  
Old 07-27-2008
One way ....
Code:
sed -e 's/ /%/g' -e 's/\(<[^>].*\)%\(.*>\)/\1 \2/g' -e 's/%/\
/g'

# 6  
Old 07-27-2008
Quote:
Originally Posted by fpmurphy
One way ....
Code:
sed -e 's/ /%/g' -e 's/\(<[^>].*\)%\(.*>\)/\1 \2/g' -e 's/%/\
/g'

Thanks man, but there's one problem, and that is, if there is more than one html tag on the line, it doesn't replace space characters only in the last one. For example: damn <here is> <the problem> transforms into this:
damn
<here
is>
<the problem>
Any idea how to deal with this?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace space with !@ using sed

Hello I have a requirement where I need to replace space :61 with !@ :61 Source :60F:123 :61:151 :61:151 :61:15101 Target :60F:123 :61:151!@:61:151!@:61:15101 I cant use and command as I don't want the tab to be converted . commands not working : sed 's/... (5 Replies)
Discussion started by: kamijia83
5 Replies

2. Shell Programming and Scripting

Replace HTML tags using sed regex

I need all the end tags of </font> to be replaced with new line yet enclosing tag to be retained </font>. Please help me in this regard. Input: <font>abc</font>def<font>ghi</font> Output: <font>abc</font> def <font>ghi</font> (3 Replies)
Discussion started by: Badhrish
3 Replies

3. UNIX for Dummies Questions & Answers

Sed- Replace space in filename by a \

`echo $file | sed 's/ / /g'` Hey guys I want help in converting the spaces in my file names to '\ ' . Example: UK maps --> UK\ maps Could someone please help me. I have tried the following sequences already (none of them work): 1)s/ /\ /g 2)s/ /\\ /g 3)s/ /\\\ /g Can someone... (7 Replies)
Discussion started by: INNSAV1
7 Replies

4. Shell Programming and Scripting

SED - insert space at the beginning of line and multi replace command

hi I am trying to use SED to replace the line matching a pattern using the command sed 'pattern c\ new line ' <file1 >file 2 I got two questions 1. how do I insert a blank space at the beginning of new line? 2. how do I use this command to execute multiple command using the -e... (5 Replies)
Discussion started by: piynik
5 Replies

5. Shell Programming and Scripting

how to replace html line into a command line?

hi! i'm trying to use sed for this, but i'm struggling a lot. i want to convert <div class="middle" id="middle">Friday, 20 April 2012<br /> <span class="hex">728CB5</span> <br /></div> into fbsetroot -solid '#728CB5' considering all information between 'id="middle">' and '<br />... (2 Replies)
Discussion started by: nitrofurano
2 Replies

6. Shell Programming and Scripting

replace space with the help of sed

Hi, i have below string - mynameis arpit i want output like below - mynameis\ arpit that i am getting from below - temp='mynameis arpit' echo $temp|sed 's//\\ /g' --> mynameis\ arpit now i am doing - (2 Replies)
Discussion started by: thearpit
2 Replies

7. Shell Programming and Scripting

Using sed I want to replace space by newline

Input: -------------------------- 123asd 456sdasda 789a ------------------------- output wanted: --------------------- 123asd 456sdasda 789a ---------------------- I want this by sed in simple way please help (I know by: tr ' ' '\n' < inputfile )I want it by sed only (5 Replies)
Discussion started by: RahulJoshi
5 Replies

8. Shell Programming and Scripting

sed : replace space and end-of-line

Hi ! I'm rather new with sed ... learned a lot already by googling etc ... The following script should replace all spaces and ends-of-lines with "something (see below). #!/bin/bash i=0 while read line do fam="H`printf "%06d" $i`" echo $line | sed -e 's//\t'$fam'\n/g' i=$(($i+1))... (7 Replies)
Discussion started by: jossojjos
7 Replies

9. Shell Programming and Scripting

how to replace new line ( \n ) with space or Tab in Sed

Hi, how to replace new line with tab in sed ... i used sed -e 's/\n/\t/g' <filename > but its not working (1 Reply)
Discussion started by: mail2sant
1 Replies

10. Shell Programming and Scripting

gnu sed replace space with new line

please help in making sed singleline command i need to insert dos new line (CR LF) before " 34 matching device(s) found on \\cpu1." " 6 matching device(s) found on \\cpu7." " 102 matching device(s) found on \\mainserver." the problem is that sometimes there are both CR LF before strings and... (1 Reply)
Discussion started by: xserg
1 Replies
Login or Register to Ask a Question