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
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
1 Like
Thanks for exercise. but above code is not converting multiline into one line.
Hmm, interesting, seems to work ok for me:
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?
1 Like
now it is working. thanks for your help
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!