473,396 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

combining multiple rows in single row based on certain condition using awk or sed

Hi,

I'm using AIX(ksh shell).

> cat temp.txt

"a","b",0
"c",bc",0
"a1","b1",0
"cc","cb",1
"cc","b2",1
"bb","bc",2

I want the output as:

"a","b","c","bc","a1","b1"
"cc","cb","cc","b2"
"bb","bc"

I want to combine multiple lines into single line where third column is same.

Is it possible through paste,sed or awk commands?

Regards,
Sam
Jul 7 '11 #1
1 7044
rski
700 Expert 512MB
If the lines you want to join are next to each other you can use that simple solution
Expand|Select|Wrap|Line Numbers
  1. awk  -F"," '
  2. BEGIN{num_old="";num_new=""}
  3. {if (num_old==""){num_old=$3;num_new=$3} else {num_new=$3} 
  4.  if (num_old==num_new){printf $1 "," $2 ","} 
  5.  if (num_old != num_new) {printf"\n";num_old=num_new;printf $1 "," $2 ","} 
  6. }
  7. END {printf "\n"} '  1.txt | sed 's/,$//g'
  8.  
If rows are not nex to each other then to use above solution you will have to sort that file by the last column or use some hash table to keep values.
Jul 11 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JB | last post by:
To anyone that is able to help.... What I am trying to do is this. I have two tables (Orders, and OrderDetails), and my question is on the order details. I would like to set up a stored...
5
by: Antanas | last post by:
Is it possible to combine multiple rows returned from select statement into one row? SELECT NAME FROM TABLE1; I want all names to be combined into one row seperated by commas.
0
by: lj | last post by:
How do I get an asp.net datagrid to set certain records as tedittemplate based on a certain condition. It is for a simple workflow. The user will have permission to see a list of records. He...
11
by: UDBDBA | last post by:
Hi: This is a merge questions which has been posted and answered... in my case need more clairification when target table (tableB) matched multiple rows to be updated based on the ON condition...
46
by: kyjabber | last post by:
I have a multi relationship database and I'm pulling the company's contact info, queryied if they are a grower, and a resulting list of their products by catgeory. I need to have the products listed...
1
by: AlexW | last post by:
Hi I have been scouring the web for some information regarding how to insert multiple rows at once using an SQL string. I am using an OLEDB dataadapter to communicate with an MS Access DB ...
1
by: boss1 | last post by:
i m having problem with inserting data into oracle db using php. i need to how to fetch fetch multiple row's data from a table in html form and insert into oracle db at a time. may be looping is...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
6
by: Jeremy Goodman | last post by:
Access 2007; Merging records containing multivalue drop down lists. I have a database showing legislation information divided by State/territory. The database needs to be able to show the info...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.