convert Multiline file in one line file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert Multiline file in one line file
# 1  
Old 07-08-2011
convert Multiline file in one line file

Hi,
Hi, we have one input file and file contain single line and multiline date. We want to convert multiline line in one line. Each file start with sequence of 000000001, 000000002, 000000003 so on. We want to convert the multiline line in one line. All (single line and converted multiline to single line) data store in output file. Please help.
***********************************************************
Ex. INPUT.txt
000000001 12335 Infinte solutiong PO box copyright
000000002 12335 Dhahran solutiong
PO box copyright
***********************************************************
************************************************************
Ex. output.txt
000000001 12335 Infinte solutiong PO box copyright
000000002 12335 Dhahrasolutiong PO box copyright
******************************************************
# 2  
Old 07-08-2011
Code:
cat multiline.txt | perl -e ' while ( <> ) { 
  chomp; 
  print "\n" if m/^\d{9}\s.*/ ;
  print "$_ ";
} 
print "\n";'

The removal of the first empty line is left as an excercise to the reader Smilie
This User Gave Thanks to Andre_Merzky For This Post:
# 3  
Old 07-08-2011
Thanks for exercise. but above code is not converting multiline into one line.
# 4  
Old 07-08-2011
Quote:
Originally Posted by humaemo
Thanks for exercise. but above code is not converting multiline into one line.
Hmm, interesting, seems to work ok for me:

Code:
merzky@thinkie:~/test/unix.com$ cat multiline.txt 
000000001 12335 Infinte solutiong PO box copyright
000000002 12335 Dhahran solutiong
PO box copyright

merzky@thinkie:~/test/unix.com$ cat multiline.txt | perl -e ' while ( <> ) { 
>   chomp; 
>   print "\n" if m/^\d{9}\s.*/ ;
>   print "$_ ";
> } 
> print "\n";'

000000001 12335 Infinte solutiong PO box copyright 
000000002 12335 Dhahran solutiong PO box copyright 
merzky@thinkie:~/test/unix.com$

What is the output you are seeing?
This User Gave Thanks to Andre_Merzky For This Post:
# 5  
Old 07-08-2011
now it is working. thanks for your help

Last edited by humaemo; 07-08-2011 at 08:30 AM..
# 6  
Old 07-08-2011
Code:
sed -e :a -e '$!N;s/\n\([^00]\)/\1/;ta' -e 'P;D' INPUT.txt


Last edited by Franklin52; 07-08-2011 at 01:51 PM.. Reason: Please use code tags for data and code samples, thank you
# 7  
Old 07-08-2011
Quote:
Originally Posted by ltomuno
sed -e :a -e '$!N;s/\n\([^00]\)/\1/;ta' -e 'P;D' INPUT.txt
Well, that is nicer and quicker than mine I think - kudos! :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove multiline HTML tags from a file?

I am trying to remove a multiline HTML tag and its contents from a few HTML files following the same basic pattern. So far using regex and sed have been unsuccessful. The HTML has a basic structure like this (with the normal HTML stuff around it): <div id="div1"> <div class="div2"> <other... (4 Replies)
Discussion started by: threesixtyfive
4 Replies

2. UNIX for Dummies Questions & Answers

Convert UNIX text file in Windows to recognize line breaks

Hi all, I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this? Or just reinsert thousands of line breaks again :eek: ? (2 Replies)
Discussion started by: frys_hp
2 Replies

3. Windows & DOS: Issues & Discussions

Convert UNIX text file in Windows to recognize line breaks

Hmmm I think I found the correct subforum to ask my question... I have some text files that I prepared in vi some time ago, and now I want to open and edit them with Windows Notepad. I don't have a Unix terminal at the moment so I need to do the conversion in Windows. Is there a way to do this?... (1 Reply)
Discussion started by: frys_hp
1 Replies

4. Shell Programming and Scripting

Multiline data from file to another file

Hello I have a file which contains following data: abc,1234,adf abc,214,fdff abc,455,adff I need to replace KEYWORD from other with following data : 1234,adf 214,fdff 455,adff (3 Replies)
Discussion started by: mayankgupta18
3 Replies

5. Shell Programming and Scripting

Remove new line character and add space to convert into fixed width file

I have a file with different record length. The file as to be converted into fixed length by appending spaces at the end of record. The length should be calculated based on the record with maximum length in the file. If the length is less than the max length, the spaces should be appended... (4 Replies)
Discussion started by: Amrutha24
4 Replies

6. Shell Programming and Scripting

how to ignore multiline comment from a file while reading it

Hi friends , I want to ignore single and multiline comment( enclosed by " \* *\" ) of a file whle reading it. I am using the below code. nawk '/\/\*/{f=1} /\*\//{f=0;next} !f' proc.txt | while read str do ... done The problem is its working partially. that is its failing in one... (1 Reply)
Discussion started by: neelmani
1 Replies

7. UNIX for Advanced & Expert Users

Problem of Multiline in csv file

Hi I have csv file which has test as multiline in the one column. ex. ---------data.csv------------ Seqno,EmpID,EmpName,Dept 1,123,"Vipin Agrawal","IT BUSINESS OFFSHORE" 2,124,"Simon Bhai","IT" The problem is name "Vipin Agrawal" has one new line character b/w name. same as Dept. ... (1 Reply)
Discussion started by: meetvipin
1 Replies

8. Shell Programming and Scripting

delete multiline string from file using sed.

Hi, I have file which has the following content... GOOD MORNING **********WARNING********** when it kicks from the kickstart, sshd daemon should start at last. (WHEN KICKING ITSELF, NOT AFTER KICKING). /etc/rc3.d/S55sshd ( run level specification for sshd is 55, now I would want to... (4 Replies)
Discussion started by: skmdu
4 Replies

9. UNIX for Advanced & Expert Users

convert one colume file to a one line, wrapped file.

I need to convert a file i.e cat list 1000: 1001: 1002: to cat wrappedfile 1000:1001:1002: currently I am using a while loop, paste and mv command to achieve desired outcome. touch wrappedfile cat list | while read line ;do echo $line > /tmp/$line;paste /tmp/$line wrappedfile >... (7 Replies)
Discussion started by: jouuu
7 Replies

10. UNIX for Dummies Questions & Answers

read a line from a csv file and convert a column to all caps

Hello experts, I am trying to read a line from a csv file that contains '.doc' and print the second column in all caps. e.g. My csv file contains: Test.doc|This is a Test|test1|tes,t2|test-3 Test2.pdf|This is a Second Test| test1|tes,t2|t-est3 while read line do echo "$line" |... (3 Replies)
Discussion started by: orahi001
3 Replies
Login or Register to Ask a Question