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

Thanks in Advance for your help.

Regards
Kalaiela

$ while read a; do echo -n "$a "; done < input.txt
I have a pen and notebook.

Hi Kamraj

Could you pls explain me how your code works. Its not working in my machine.I got the output as below.

> while read a; do echo -n "$a "; done < input.txt
-n I have a
-n pen and
-n notebook.

More over my input file is like below.
I have a
pen and
notebook.

I have a
pen and
notebook.
Like this it is repeating with two blank lines in the middle.
what i want is
I have a pen and notebook.
I have a pen and notebook.

Thanks in Advance.

cat FILE
I have a
pen and
notebook.

I have a
pen and
notebook.
                                                                          ~
perl -00 -pe 's/\n/ /g; s/ $/\n/' FILE
I have a pen and notebook.
I have a pen and notebook.
 
$ cat file
I have a
pen and
notebook.
 
$ perl -pe 's/\n/ /g;' file
I have a pen and notebook.

if you want output in another file, you can simplye redirect it

 
$ perl -pe 's/\n/ /g;' file > file1

Njoy!! :wink: