Help with merging data into single line.

Hi,

My input is

[input]
<message>
looking for a big
<message>Does fit my G74 laptop.  Makes the 10 pound.
<message>
<message>This bag is the only one I could find to fit my awesome ASUS G74S.
<message>
<message>
Great bag my only wish is that they had put a pocket in which to store and protect your earphone buds when you sleeve them through the shoulder strap as my Bose earpieces tend to fall off if not in my ear. However that's more a problem with my earphones than the bag. (easy solution.
<message>Have a G73SW laptop, and was using a messenger bag for transport mostly due to the difficulty in finding a solid transporter for the beast.  After reading rev
[/input

and i need output is

[output]
<message>looking for a big
<message>Does fit my G74 laptop.  Makes the 10 pound.
<message>
<message>This bag is the only one I could find to fit my awesome ASUS G74S.
<message>
<message>Great bag my only wish is that they had put a pocket in which to store and protect your earphone buds when you sleeve them through the shoulder strap as my Bose earpieces tend to fall off if not in my ear. However that's more a problem with my earphones than the bag. (easy solution.
<message>Have a G73SW laptop, and was using a messenger bag for transport mostly due to the difficulty in finding a solid transporter for the beast.  After reading rev
[/output]

thanks for your help...

# awk '/<message>/{x=$0;if(getline)if($0!~/^<message>/)printf "%s%s\n",x,$0;else print x"\n"$0}END{print}' infile
<message>looking for a big
<message>Does fit my G74 laptop. Makes the 10 pound.
<message>
<message>This bag is the only one I could find to fit my awesome ASUS G74S.
<message>
<message>Great bag my only wish is that they had put a pocket in which to store and protect your earphone buds when you sleeve them through the shoulder strap as my Bose earpieces tend to fall off if not in my ear. However that's more a problem with my earphones than the bag. (easy solution.
<message>Have a G73SW laptop, and was using a messenger bag for transport mostly due to the difficulty in finding a solid transporter for the beast. After reading rev
1 Like

try:

awk 'END{print RS} /^</{if(NR>1)print RS}1' ORS= infile
1 Like

Thanks guys but one issue i m getting all the data in one line i want the line should start with <message>....

please help.....

I am getting this:

$ awk 'END{print RS} /^</{if(NR>1)print RS}1' ORS= infile
<message>looking for a big
<message>Does fit my G74 laptop.  Makes the 10 pound.
<message>
<message>This bag is the only one I could find to fit my awesome ASUS G74S.
<message>
<message>Great bag my only wish is that they had put a pocket in which to store and protect your earphone buds when you sleeve them through the shoulder strap as my Bose earpieces tend to fall off if not in my ear. However that's more a problem with my earphones than the bag. (easy solution.
<message>Have a G73SW laptop, and was using a messenger bag for transport mostly due to the difficulty in finding a solid transporter for the beast.  After reading rev

Is that not what you are getting? What is your OS and version?

How ?

# awk '/<message>/{x=$0;if(getline)if($0!~/^<message>/)printf "%s%s\n",x,$0;else print x"\n"$0}END{print}' file|cat -n
     1  <message>looking for a big
     2  <message>Does fit my G74 laptop.  Makes the 10 pound.
     3  <message>
     4  <message>This bag is the only one I could find to fit my awesome ASUS G74S.
     5  <message>
     6  <message>Great bag my only wish is that they had put a pocket in which to store and protect your earphone buds when you sleeve them through the shoulder strap as my Bose earpieces tend to fall off if not in my ear. However that's more a problem with my earphones than the bag. (easy solution.
     7  <message>Have a G73SW laptop, and was using a messenger bag for transport mostly due to the difficulty in finding a solid transporter for the beast.  After reading rev
# awk 'END{print RS} /^</{if(NR>1)print RS}1' ORS= file|cat -n
     1  <message>looking for a big
     2  <message>Does fit my G74 laptop.  Makes the 10 pound.
     3  <message>
     4  <message>This bag is the only one I could find to fit my awesome ASUS G74S.
     5  <message>
     6  <message>Great bag my only wish is that they had put a pocket in which to store and protect your earphone buds when you sleeve them through the shoulder strap as my Bose earpieces tend to fall off if not in my ear. However that's more a problem with my earphones than the bag. (easy solution.
     7  <message>Have a G73SW laptop, and was using a messenger bag for transport mostly due to the difficulty in finding a solid transporter for the beast.  After reading rev

Sorry guys... i m trying to execute this script on data which starts with tab. like

    <message>
    looking for a big
    <message>Does fit my G74 laptop.  Makes the 10 pound.
    <message>

It working as expected thanks a lot...:slight_smile: