Arrange values of a column in row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Arrange values of a column in row
# 1  
Old 06-14-2011
Arrange values of a column in row

HI,

I need to arrange values of a colum in row.

e.g.

input file :

Alpha<>123
AAAA<>6754
Beta<>456
BBBB<>63784
CCC<>783
Gama<>789
Alpha<>555
AAAA<>6754
BBBB<>63784
Beta<>666
CCC<>783
Gama<>888
.
.
.

desired output:

Alpha<>123 | Beta<>456 | Gama<>789 |
Alpha<>555 | Beta<>666 | Gama<>888 |
.
.
.

Thanks in advance
Archer
# 2  
Old 06-14-2011
something like :

Code:
#  paste - - - < infile
Alpha<>123      AAAA<>6754      Beta<>456
BBBB<>63784     CCC<>783        Gama<>789
Alpha<>555      AAAA<>6754      BBBB<>63784
Beta<>666       CCC<>783        Gama<>888

or 

#  paste -d"|" - - - < infile
Alpha<>123|AAAA<>6754|Beta<>456
BBBB<>63784|CCC<>783|Gama<>789
Alpha<>555|AAAA<>6754|BBBB<>63784
Beta<>666|CCC<>783|Gama<>888

what you're after ? Or are you only wanting specific lines/regexps ?

what is exact format of infile / outfile

HTH
# 3  
Old 06-14-2011
@The_Archer: What happend to "AAA" , "BBB" and "CCC" columns ?

Last edited by panyam; 06-14-2011 at 11:28 AM.. Reason: edited to ask question to OP
# 4  
Old 06-14-2011
Like this?
Code:
paste -d'|' <(grep Alpha input) <(grep Beta input) <(grep Gama input)

# 5  
Old 06-14-2011
This will help your requirement Smilie

Code:
sort input.txt|sed 's/^./& /g'|nawk '{if(NR!=1 && $1 != prev) {ORS="\n";print;prev=$1} else {ORS=":";print;prev=$1}}'|sed 's/ //g'

Thanks
Sha
# 6  
Old 06-15-2011
Quote:
Originally Posted by panyam
@The_Archer: What happend to "AAA" , "BBB" and "CCC" columns ?

"AAA" , "BBB" and "CCC" columns values need to be discard

---------- Post updated at 06:40 PM ---------- Previous update was at 06:39 PM ----------

Quote:
Originally Posted by Shahul
This will help your requirement Smilie

Code:
sort input.txt|sed 's/^./& /g'|nawk '{if(NR!=1 && $1 != prev) {ORS="\n";print;prev=$1} else {ORS=":";print;prev=$1}}'|sed 's/ //g'

Thanks
Sha

Thanks Sha

but i donot need to sort the coloum ,
as every Alpha is associated with its beta & Gamma under it
# 7  
Old 06-15-2011
How about this

Code:
 
perl -0ne 'print "$1 | $2 | $3 |\n" while (/(Alpha<>\d+).*?(Beta<>\d+).*?(Gama<>\d+).*?/sg)' input


Last edited by getmmg; 06-15-2011 at 11:13 AM.. Reason: Added | at the end
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to add one to each row values and keep it after the value in the column?

Dear Folks Hello I have a column of numbers, say: 26 79 68 I want to add one to each row value and get this desire column: 26 27 79 80 68 69 (6 Replies)
Discussion started by: sajmar
6 Replies

2. UNIX for Dummies Questions & Answers

Unique values in a row sum the next column in UNIX

Hi would like to ask you guys any advise regarding my problem I have this kind of data file.txt 111111111,20 111111111,50 222222222,70 333333333,40 444444444,10 444444444,20 I need to get this file1.txt 111111111,70 222222222,70 333333333,40 444444444,30 using this code I can... (6 Replies)
Discussion started by: reks
6 Replies

3. Shell Programming and Scripting

Parsing Column Values in Row

Hi , I have been trying to write a awk script which will have the following Output 1. Append the last Characters of the lines matching pattern xxxxxxxxx & then a space & then Append the last Characters of the lines matching pattern yyyyyyyyy 2. the process will continue till end of file &... (10 Replies)
Discussion started by: newageBATMAN
10 Replies

4. Shell Programming and Scripting

Move values from column to row

Hello guys. Please can you help me with this.. Thanks in advance:b: Input file 2134 6371 N 2150 6371 M 2166 6371 S 2138 6417 N 2154 6417 M 2170 6417 S 2157 6603 N 2173 6603 M 2189 6603 S desired uotput 6371 2134N 2150M 2166S 6417 2138N 2154M 2170S... (2 Replies)
Discussion started by: jiam912
2 Replies

5. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

Deleting row if all column values are a particular string

Hello, I have a very large file for which I would like to remove all rows for which the value of columns 2-5 is zero. For instance I would like this file: contig1, 0, 0, 0, 0 contig2, 1, 3, 5, 0 contig3, 0, 0, 0, 0 contig4, 0, 5, 6, 7 To become this file: contig2, 1, 3, 5,0 ... (17 Replies)
Discussion started by: mouchkam
17 Replies

7. Shell Programming and Scripting

Find and replace duplicate column values in a row

I have file which as 12 columns and values like this 1,2,3,4,5 a,b,c,d,e b,c,a,e,f a,b,e,a,h if you see the first column has duplicate values, I need to identify (print it to console) the duplicate value (which is 'a') and also remove duplicate values like below. I could be in two... (5 Replies)
Discussion started by: nuthalapati
5 Replies

8. Shell Programming and Scripting

Converting values in a ROW to COLUMN

Hi All, I needd to convert values in a row to a column. eg: Input is as: value1,value2,value3,value4,.........,value N Required Output: Value1 Value2 Value3 . . . Value N Please help.... (3 Replies)
Discussion started by: sambaman
3 Replies

9. Shell Programming and Scripting

Convert column values into row

hi, I have a requirement where in I read the values from a file using awk. The resulting data should be converted into row format from column format. For ex: My log file login.lst contains the following SERVER1 DB1 SERVER2 DB2 SERVER3 DB3 SERVER4 DB4 I use awk to grep only the server... (6 Replies)
Discussion started by: senthil3d
6 Replies

10. Shell Programming and Scripting

Concatenating column values with unique id into single row

Hi, I have a table in Db2 with data say id_1 phase1 id_1 phase2 id_1 phase3 id_2 phase1 id_2 phase2 I need to concatenate the values like id_1 phase1,phase2,phase3 id_2 phase1,phase2 I tried recursive query but in vain as the length of string to be concatenated in quite long. ... (17 Replies)
Discussion started by: jsaravana
17 Replies
Login or Register to Ask a Question