Break lines up into single lines after each space in every line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Break lines up into single lines after each space in every line
# 1  
Old 10-14-2009
Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space.

Example of text file;
line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none repeat scroll 0% 0%; }
line2 .digg-widget-theme2 li { color: rgb(102, 102, 102); }
line3 .digg-widget-theme3 { border-color: rgb(221, 221, 221); }
line4 .digg-widget-theme3 ul h3 a:link, .digg-widget-theme3 ul h3 a:visited, .digg-widget-theme3 ul h3 a:active { color: rgb(73, 124, 172) ! important; }
line5 .digg-widget-theme3 ul h3 a:hover { color: rgb(0, 0, 0) ! important; }
line 6 .digg-widget-theme3 .digg-widget-header, .digg-widget-theme3 .digg-widget-footer, .digg-widget-theme3 .digg-widget-topic { background: rgb(204, 204, 204) none

What I want to achieve:

Line1 for example;

.digg-widget-theme2
ul
{
background:
rgb(0,
0,
0)
none
repeat
scroll
0%
0%;
}

Line2 for example;
.digg-widget-theme2
li
{
color:
rgb(102,
102,
102);
}

The end result should look like this (Included the examples above);

ul
{
background:
rgb(0,
0,
0)
none
repeat
scroll
0%
0%;
}
.digg-widget-theme2
li
{
color:
rgb(102,
102,
102);
}
# 2  
Old 10-14-2009
This is what you are looking for.,

Code:
sed 's/ /\n/g' input-file

So output as expected, ( example, not the whole )

Code:
.digg-widget-theme2
ul
{
background:
rgb(0,
0,
0)
none
repeat
scroll
0%
0%;
}

# 3  
Old 10-14-2009
Hi Geek,

I was also trying the solution for the above one.. even though i was trying your solution, i was not getting the result. can you tell me where i am going wrong.

Code:
d>cat a.txt
.digg-widget-theme2 ul { background: rgb(0, 0, 0) none repeat scroll 0% 0%; }
.digg-widget-theme2 li { color: rgb(102, 102, 102); }
d>sed 's/ /\n/g' a.txt
.digg-widget-theme2nuln{nbackground:nrgb(0,n0,n0)nnonenrepeatnscrolln0%n0%;n}
.digg-widget-theme2nlin{ncolor:nrgb(102,n102,n102);n}

# 4  
Old 10-14-2009
@thegeek woah! It worked super fine, thanks man!

---------- Post updated at 02:46 PM ---------- Previous update was at 02:03 PM ----------

Quote:
Originally Posted by mac4rfree
Hi Geek,

I was also trying the solution for the above one.. even though i was trying your solution, i was not getting the result. can you tell me where i am going wrong.

Code:
d>cat a.txt
.digg-widget-theme2 ul { background: rgb(0, 0, 0) none repeat scroll 0% 0%; }
.digg-widget-theme2 li { color: rgb(102, 102, 102); }
d>sed 's/ /\n/g' a.txt
.digg-widget-theme2nuln{nbackground:nrgb(0,n0,n0)nnonenrepeatnscrolln0%n0%;n}
.digg-widget-theme2nlin{ncolor:nrgb(102,n102,n102);n}

Strange that it is not working for you. Are you trying it from a UNIX prompt? Can't think that the type of shell would influence it but I tried it on a BASH shell.

Maybe try on another box and see?
# 5  
Old 10-14-2009
don knw.. earlier i tried in SunOs.. But this time, i tried in AIX.. still the same result...
what is your OS?
# 6  
Old 10-14-2009
Code:
awk '{print $0}' RS=" " e.txt

# 7  
Old 10-14-2009
Code:
tr -s ' ' '\n' < myFile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break line content into multiple lines using delimiter

I need to break the line after every 3rd semi colon(;) using Unix shell scripting Input.txt ABC;DEF;JHY;LKU;QWE;BVF;RGHY; Output.txt ABC;DEF;JHY; LKU;QWE;BVF; RGHY; (1 Reply)
Discussion started by: meet_calramz
1 Replies

2. Shell Programming and Scripting

Enumerate lines until each line break using awk

Hi, I have the following data: This this DT 0.99955 0 4 is be VBZ 1 5 7 sentence sentence NN 0.916667 8 16 one one NN 0.545078 17 20 . . Fp 1 20 21 This this DT 0.99955 22 26 is be VBZ 1 27 29 the the DT 1 30 33 second 2 JJ 0.930556 34 40 sentence sentence NN 0.916667 41 49... (1 Reply)
Discussion started by: owwow14
1 Replies

3. Shell Programming and Scripting

Write the lines in one single line

Hi, I need some iteration to do the following work. Sample: ANS|26-Jan-2012|26|MON|12536.1 ANS|26-Jan-2012|26|TUE|2536.1 ANS|26-Jan-2012|26|THUR|789.1 SED|26-Jan-2013|32|MON|258.1 SED|26-Jan-2013|32|TUE|369.1 SED|26-Jan-2013|32|THUR|2145.1 OUTPUT: ... (3 Replies)
Discussion started by: anshaa
3 Replies

4. UNIX for Dummies Questions & Answers

Replacing 2 lines by single line

Hi I have a file with below content : a b S I need to replace the lines which have a and b continuously by d. d S I have used the below code tr '\n' '#'<file|sed. 's/a#b/d/g's?|tr '#' '\n' where # is not occurring anywhere in the file.. Is there any other efficient way to do this? ... (7 Replies)
Discussion started by: pandeesh
7 Replies

5. Shell Programming and Scripting

Multi lines to single line

HI, My input file contains the data as like below: A1234119993 B6271113 Bghjkjk A1234119992 B6271113hi Bghjkjkmkl the output i require is : A1234119993 B6271113 Bghjkjk A1234119992 B6271113hi Bghjkjkmkl Please help me in this. Thanks (6 Replies)
Discussion started by: pandeesh
6 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. Shell Programming and Scripting

Awk to Break lines to multiple lines.

Input File: nawk -F "|" '{ for(i=1;i<=NF;i++) { if (i == 2) {gsub(",","#",$i);z=split($i,a,"")} else if (i == 3) {gsub(",","#",$i);z=split($i,b,"")} } if(z > 0) for(i=1;i<=z;i++) print $1,a,"Test"; if(w > 0) for(j=1;j<=w;j++) ... (1 Reply)
Discussion started by: pinnacle
1 Replies

8. Shell Programming and Scripting

join lines on line break in files

i had a file where lines appear to be broken when they shouldn't eg Line 1. kerl abc sdskd sdsjkdlsd sdsdksd \ Line 2. ksdkks sdnjs djsdjsd i can do a shift join to combine the lines but i there are plenty of files with this issue Line 1. kerl abc sdskd sdsjkdlsd sdsdksd ksdkks sdnjs... (6 Replies)
Discussion started by: mad_man12
6 Replies

9. Shell Programming and Scripting

Break one line to many lines using awk

Break one line to many lines using awk The below code works but i want to implement without combining field 2 and 3 and then splitting i would like to do this in one command instead of writing multiple commands and creating multiple lines. nawk -F"|" '{print $1,$2SUBSEP$3}' OFS="|" file >... (16 Replies)
Discussion started by: pinnacle
16 Replies

10. UNIX for Dummies Questions & Answers

Joining lines to single line in VI

Dear friends, In VI, I have these data shown below: Line1 Line2 Line3 Line4 How can I JOIN these line to the first line? When I finished I should have: Line1 Line2 Line3 Line4 is there a text length limit of how long a single line can be in VI? Thank you much! (10 Replies)
Discussion started by: bobo
10 Replies
Login or Register to Ask a Question