Sample input (line feed indicated by [LF])
---------------
The red fox jumped [LF]
over the brown fence of the [LF]
red hous [LF]
[LF]
[LF]
[LF]
He then went into the[LF]
orchard[LF]
[LF]
---------------
Desired Output
---------------
The red fox jumped over the brown fence of the red house
[LF]
He then went into the orchard
[LF]
any input on a sed/awk one liner to achieve this would be immensely helpful
cfajohnson, your solution removed all the blank lines......
summer_cherry: I tried playing around with your solution. It came closest to what I am looking for, but I guess my requirements are a little more complicated and I didn't outline them correctly before.
Here's what I have done so far
1> remove all blank lines using sed -e 's/^$//g' file.txt > file1.txt
2> Now I have file in the following format (delimiter indicated by DL, Line Feed by LF)
------------------------
Sample Input
------------------------
[DL]
The fox jumped over the red[LF]
fence into[LF]
the orchard to eat some[LF]
grapes[LF]
[DL]
Then it came back to the[LF]
yard to hunt some[LF]
sheep[LF]
[DL]
The farmer chased[LF]
the fox away[LF]
---------------------
Expected Output
---------------------
[DL]
The fox jumped over the red fence into the orchard to eat some grapes
[DL]
Then it came back to the yard to hunt some sheep
[DL]
The farmer chased the fox away
I am also trying to achieve this output, but I have failed with various sed solutions that I have tried.
-------------------------
SAMPLE INPUT
-------------------------
Name: ABCD
Address: ABCD Road, ABCD City, ABCD State
ZipCode: 0000
Telno: 999-999-9999
Name: EFGH
Address Temp Road, Temp City, Temp State
Telno 999-999-9999
No, I don't know for which record I would need to insert the missing field.
I know the order of fields in a record.
So if any field is missing in a record, insert it at an appropriate place in that record.
Do the same for all records.
Also the data for each field would be split across multiple lines. So your solution of print;getline; won't work. There is no way of knowing how many lines the data would span.
> cat file5
The red fox jumped
over the crazy lazy dog
at the red house
and then he went
to eat, at
Gramma's house he went
to eat
and eat
and eat some more
> cat file5 | awk '{if ($0!=""){lin=lin" "$0}else{if(lin!=""){print lin};lin=""}}'
The red fox jumped over the crazy lazy dog at the red house
and then he went to eat, at Gramma's house he went
to eat and eat and eat some more
undef $/;
open $fh,"<","a.spl" or die "Can not open file";
$str=<$fh>;
my @arr=split(/\[DL\]/,$str);
map {my $tmp=$_; $tmp=~s/\n/ /g; print "\n[DL]\n",$tmp if $tmp ne ""} @arr;