Combining lines into a single line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combining lines into a single line
# 1  
Old 06-16-2017
Combining lines into a single line

i have a file (where the column values are separated by ' and the text can be enclosed in ~) which contains data in form of

Code:
4461,2,~Basic: 
        2 Years/Unlimited Miles

Drivetrain: 
        Gas Engine
        2 Years/Unlimited Miles
        Duramax Engine
        3 Years/Unlimited Miles
        Caterpillar Engine
        3 Years/150,000 Miles

        Manual Trans
        2 Years/Unlimited Miles
        Auto Trans MT643/MT653/MD3060/MD3560
        2 Years/Unlimited Miles
        Auto Trans AT545/2000P/2400P
        3 Years/Unlimited Miles

Corrosion: 
        5 Years/Unlimited Miles~
4457,2,~Basic: 
        2 Years/Unlimited Miles

Drivetrain: 
        Gas Engine
        2 Years/Unlimited Miles
        Duramax Engine
        3 Years/Unlimited Miles
        Caterpillar Engine
        3 Years/150,000 Miles

        Manual Trans
        2 Years/Unlimited Miles
        Auto Trans MT643/MT653/MD3060/MD3560
        2 Years/Unlimited Miles
        Auto Trans AT545/2000P/2400P
        3 Years/Unlimited Miles

Corrosion: 
        5 Years/Unlimited Miles~

now i need to convert the file data in

Code:
4461,2,~Basic:         2 Years/Unlimited Miles Drivetrain:         Gas Engine        2 Years/Unlimited Miles        Duramax Engine        3 Years/Unlimited Miles        Caterpillar Engine        3 Years/150,000 Miles        Manual Trans        2 Years/Unlimited Miles        Auto Trans MT643/MT653/MD3060/MD3560        2 Years/Unlimited Miles        Auto Trans AT545/2000P/2400P        3 Years/Unlimited MilesCorrosion:         5 Years/Unlimited Miles~
4457,2,~Basic:         2 Years/Unlimited MilesDrivetrain:         Gas Engine        2 Years/Unlimited Miles        Duramax Engine        3 Years/Unlimited Miles        Caterpillar Engine        3 Years/150,000 Miles        Manual Trans        2 Years/Unlimited Miles        Auto Trans MT643/MT653/MD3060/MD3560        2 Years/Unlimited Miles        Auto Trans AT545/2000P/2400P        3 Years/Unlimited MilesCorrosion:         5 Years/Unlimited Miles~

Moderator's Comments:
Mod Comment Please use code tags

Last edited by jim mcnamara; 06-16-2017 at 01:53 PM.. Reason: code tags
# 2  
Old 06-16-2017
Have you tried anything? for a start you can use a Basic: as a flag and only print newlines when your extended newly created line ends line ends
Code:
awk 'FNR==1  {printf("%s ", $0); next }    # print the first line with no newline  and continue reading the next line first time we see Basic:
       /Basic:$/  {print ""}  # print new line because we already came to the end, this is the second time we see Basic:
       Here you print each line with no newline - you code it.
       END{print "" }   # print the last newline   because there are no more line to read
      '  inputfile > outputfile

# 3  
Old 06-16-2017
Try also
Code:
awk '/Basic/ && NR > 1 {printf RS} 1; END {printf RS}' ORS="" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Log4j combining lines to single line

Hi, Our log4j file contents look like this: 2018-11-20T00:06:58,888 INFO ql.Driver: Executing command(queryId=hive_20181120000656_49af4ad0-1d37-4312-872c-a247ed80c181): CREATE TABLE RESULTS.E7014485_ALL_HMS_CAP1 AS SELECT name,dept from employee Where employee='Jeff'... (4 Replies)
Discussion started by: wahi80
4 Replies

2. UNIX for Beginners Questions & Answers

Combining lines in one line

Hi below is the input file snippet. here i want that all the line which is coming after 1 shoud be in one line. so for exanple if after 1 there is two lines which is starting with 2 should be combine in one line. input file content 1,8091012,BATCH_1430903_01,21,T,2,808738,,,,21121:87:01,... (19 Replies)
Discussion started by: scriptor
19 Replies

3. Shell Programming and Scripting

Combining multiple block of lines in one comma separated line

Hi Everyone, On my Linux box I have a text file having block of few lines and this block lines separated by one blank line. I would like to format and print these lines in such a way that this entire block of lines will come as single comma separated line & again next block of lines in next... (7 Replies)
Discussion started by: gr8_usk
7 Replies

4. UNIX for Dummies Questions & Answers

Need help combining txt files w/ multiple lines into csv single cell - also need data merge

:confused:Hello -- i just joined the forums. I am a complete noob -- only about 1 week into learning how to program anything... and starting with linux. I am working in Linux terminal. I have a folder with a bunch of txt files. Each file has several lines of html code. I want to combine... (2 Replies)
Discussion started by: jetsetter
2 Replies

5. Shell Programming and Scripting

Combining lines in to one line

Hi Friends, I have a file1.txt 1001 jkilo yrhfm 200056 jhdf rjhwjkrh 3+u8jk5h3 uru ehjk 1002 jkfhk hfjkd 2748395 fdjksfh hefjkh 3hdfk ejkh kjhjke In the above if you see the firt charcter of each line mentioned in red has a pattern . I need to create another file where , the... (6 Replies)
Discussion started by: i150371485
6 Replies

6. Programming

PERL:Combining multiple lines to single line

Hi All I need a small help for the below format in making a small script in Perl or Shell. I have a file in which a single line entries are broken into three line entries. Eg: I have a pen and notebook. All i want is to capture in a single line in a separate file. eg: I have a pen and... (4 Replies)
Discussion started by: Kalaiela
4 Replies

7. Shell Programming and Scripting

Combining 2 lines in a file into 1 line

Hi all, I have a file with lot of lines with repeating pattern. ( TABLE_NAME line followed by Total line). I would like combine these two lines into one line seperated by cama and create a new file. Is there a simple way to do this. Current Format ( just a sample 4 lines ) TABLE_NAME:... (10 Replies)
Discussion started by: MKNENI
10 Replies

8. 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

9. Shell Programming and Scripting

split single line into two line or three lines

Dear All, I want to split single line into two line or three lines wherever “|” separated values comes using Input line test,DEMTEMPUT20100404010012,,,,,,,,|0070086|0070087, output shoule be test,DEMTEMPUT20100404010012,,,,,,,,0070086, test,DEMTEMPUT20100404010012,,,,,,,,0070087, (14 Replies)
Discussion started by: arvindng
14 Replies

10. Shell Programming and Scripting

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... (7 Replies)
Discussion started by: lewk
7 Replies
Login or Register to Ask a Question