Help with merging data into single line.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with merging data into single line.
# 1  
Old 06-19-2012
Help with merging data into single line.

Hi,

My input is
Code:
[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&apos;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
Code:
[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&apos;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...
# 2  
Old 06-19-2012
Code:
# 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&apos;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

This User Gave Thanks to ygemici For This Post:
# 3  
Old 06-19-2012
try:
Code:
awk 'END{print RS} /^</{if(NR>1)print RS}1' ORS= infile


Last edited by Scrutinizer; 06-19-2012 at 07:53 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 06-19-2012
Thanks guys but one issue i m getting all the data in one line i want the line should start with <message>....

please help.....
# 5  
Old 06-19-2012
I am getting this:

Code:
$ 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&apos;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?
# 6  
Old 06-19-2012
Quote:
Originally Posted by pamu
Thanks guys but one issue i m getting all the data in one line i want the line should start with <message>....

please help.....
How ?
Code:
# 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&apos;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

Code:
# 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&apos;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

# 7  
Old 06-19-2012
Sorry guys... i m trying to execute this script on data which starts with tab. like
Code:
    <message>
    looking for a big
    <message>Does fit my G74 laptop.  Makes the 10 pound.
    <message>

It working as expected thanks a lot...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merging multiple lines into single line based on one column

I Want to merge multiple lines based on the 1st field and keep into single record. SRC File: AAA_POC_DB.TAB1 AAA_POC_DB.TAB2 AAA_POC_DB.TAB3 AAA_POC_DB.TAB4 BBB_POC_DB.TAB1 BBB_POC_DB.TAB2 CCC_POC_DB.TAB6 OUTPUT ----------------- 'AAA_POC_DB','TAB1','TAB2','TAB3','TAB4'... (10 Replies)
Discussion started by: raju2016
10 Replies

2. UNIX for Dummies Questions & Answers

How to generate one long column by merging two separate two columns in a single file?

Dear all, I have a simple question. I have a file like below (separated by tab): col1 col2 col3 col4 col5 col6 col7 21 66745 rs1234 21 rs5678 23334 0.89 21 66745 rs2334 21 rs9978 23334 0.89 21 66745 ... (4 Replies)
Discussion started by: forevertl
4 Replies

3. Shell Programming and Scripting

Merging the flat files into a single file

Hi, My requirement is search for the flat files in the location that are generated in a day and merge them into a single flat file. In the merged file as well particular column value should go into particular column. awk 'NR=1 FNR>1' $(ls -rt flatfile1_v_*) when i use this command for... (4 Replies)
Discussion started by: srikanth_sagi
4 Replies

4. Shell Programming and Scripting

Merging two files with merging line by line

Hi, I have two files and i want to merge it like, file1.txt --------- abc cde efg file2.txt ------- 111 222 333 Output file should be, -------------- abc 111 (2 Replies)
Discussion started by: rbalaj16
2 Replies

5. Shell Programming and Scripting

merging multiple lines into single line

Hi, 1. Each message starts with date 2. There is blank line between each message 3. Each message does not contain same number of lines. Any help in merging multiple lines in each message to a single line is much appreciated. AIX: Korn Shell Error log file looks like below. ... (5 Replies)
Discussion started by: bala123
5 Replies

6. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

7. Shell Programming and Scripting

Merging information from multiple files to a single file

Hello, I am new to unix and need help with a problem. I have 2 files each containing multiple columns of information ie; File 1 : A B C D E 1 2 3 4 5 File 2 : F G 6 7 I would like to merge the information from File 2 to File 1 so that the data reads as follows; File 1: A... (4 Replies)
Discussion started by: crunchie
4 Replies

8. Shell Programming and Scripting

Merging files into a single tab delimited file with a space separating

I have a folder that contains say 50 files in a sequential order: cdf_1.txt cdf_2.txt cdf_3.txt cdf_3.txt . . . cdf_50.txt. I need to merge these files in the same order into a single tab delimited file. I used the following shell script: for x in {1..50}; do cat cdf_${x}.txt >>... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

9. Shell Programming and Scripting

merging similar columns in a single line file

Hi Guys. I have tried the commands sort and join. But I couldn't able to to find the command for joining in a single line based on keys.My example inputs and outputs are like the following. Help would be appreciated.:D Input file a1tabXXXXXXX a2tabXXXXXXX a6tabYYYYYYYYY a71tabXXXXXXX... (7 Replies)
Discussion started by: repinementer
7 Replies

10. UNIX for Advanced & Expert Users

Merging two command into single line

1. du -sch int* | grep "total" | awk '{print $1}' first command result is 17K 2. echo "B" Result B i want the output is 17KB (2 Replies)
Discussion started by: kingganesh04
2 Replies
Login or Register to Ask a Question