Change col to row using shell script..Very Complex


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change col to row using shell script..Very Complex
# 1  
Old 07-18-2012
Bug Change row to col using shell script

Hi guys

I have file A with Below Data
Code:
ABC123	X1  X2  X3 
ABC123	Y1 Y33 Y4
ABC123	Z1 ZS2 ZL3
ABC234	P1 PP3 PP9
ABC234	Q1
ABC234	R1 P09 PO332 PO331 OKI12  
..
..
..

Now I want file B as below


Code:
ABC123	X1 X2 X3;Y1 Y33 Y4;Z1 ZS2 ZL3
ABC234	P1 PP3 PP9;Q1;R1 P09 PO332 PO331 OKI12

Thanks in Advance

Last edited by methyl; 07-18-2012 at 11:12 PM.. Reason: please use code tags
# 2  
Old 07-18-2012
Code:
awk '{t=$1;$1="";a[t]=a[t]$0";"}END{for(i in a)print i,a[i]}' infile | sed 's/;$//'

This User Gave Thanks to complex.invoke For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Read values in each col starting 3rd row.Print occurrence value.

Hello Friends, Hope all are doing fine. Here is a tricky issue. my input file is like this 07 10 14 20 21 03 15 27 30 32 01 10 11 19 30 02 06 14 15 17 01 06 20 25 29 Logic: 1. Please print another column as "0-0-0-0-0" for the first and second rows. 2. Read the first column... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

2. Shell Programming and Scripting

How to mark the row based on col value.?

Hi Gurus, I have requirement to identify the records based on one column value. the sample file as below: ID AMT, AMT1 100,10, 2 100,20, 3 200,30, 0 200, 40, 0 300, 20, 2 300, 50, 2 400, 20, 1 400, 60, 0 for each ID, there 2 records, if any one record amt1 is 0, the in 4th col add... (5 Replies)
Discussion started by: ken6503
5 Replies

3. Shell Programming and Scripting

Shell script to read little complex values

Dear All, I have attached a file. In that I want to read some of the values like 1. ExecutionTime 2. ClockTime etc. I want to read at a specified time. How can I do that? Thanks & Regards, linuxUser_ (9 Replies)
Discussion started by: linuxUser_
9 Replies

4. Shell Programming and Scripting

Complex calulation in shell script

Hi , I need one help to do some complex calculation in shell script. here is what i need to do:- a=2 b=2 c=2 d=2 result=a+(b/(20*c))+(c/(10*d)) is there any thing special there so that i can group intermdiate results. Please help me if you have any idea. (4 Replies)
Discussion started by: harpal singh
4 Replies

5. Shell Programming and Scripting

Modifying col values based on another col

Hi, Please help with this. I have several excel files (with and .xlsx format) with 10-15 columns each. They all have the same type of data but the columns are not ordered in the same way. Here is a 3 column example. What I want to do add the alphabet from column 2 to column 3, provided... (9 Replies)
Discussion started by: newbie83
9 Replies

6. Shell Programming and Scripting

Printing from col x to end of line, except last col

Hello, I have some tab delimited data and I need to move the last col. I could hard code it, awk '{ print $1,$NF,$2,$3,$4,etc }' infile > outfile but it would be nice to know the syntax to print a range cols. I know in cut you can do, cut -f 1,4-8,11- to print fields 1,... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

7. UNIX for Dummies Questions & Answers

how to join files with diff col # and row #?

I am a new user of Unix/Linux, so this question might be a bit simple! I am trying to join two (very large) files that both have different # of cols and rows in each file. I want to keep 'all' rows and 'all' cols from both files in the joint file, and the primary key variables are in the rows.... (1 Reply)
Discussion started by: BNasir
1 Replies

8. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

9. UNIX for Advanced & Expert Users

Print line based on highest value of col (B) and repetion of values in col (A)

Hello everyone, I am writing a script to process data from the ATP world tour. I have a file which contains: t=540 y=2011 r=1 p=N409 t=540 y=2011 r=2 p=N409 t=540 y=2011 r=3 p=N409 t=540 y=2011 r=4 p=N409 t=520 y=2011 r=1 p=N409 t=520 y=2011 r=2 p=N409 t=520 y=2011 r=3 p=N409 The... (4 Replies)
Discussion started by: imahmoud
4 Replies

10. Shell Programming and Scripting

shell script add each row value

Hi, I wrote below small script which will add up each row value from a file and print the total, but it is not.plz let me know what is wrong.script hangs and not displaying anything. ----------------- while read line ; do sum=0; sum=$sum+$line; done echo $sum; exit 0; ------------------... (8 Replies)
Discussion started by: pradeep_script
8 Replies
Login or Register to Ask a Question