Find and transpose


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and transpose
# 1  
Old 06-27-2014
Find and transpose

Dear All
I was wondering how to resolve an issue that I met during my analysis. In particular I have a file like this(tab separated):
Code:
factor1 element1 chr1 309343146 330945480 1 protein_coding geneA
factor2 element2 chr2 309350853 309603230 1 protein_coding geneA
factor3 element3 chr3 1815821403 1815952803 1 protein_coding geneB
factor4 element4 chr4 1815961868 1816655660 1 protein_coding geneB

What I would like to obtain is a file like this:
Code:
geneA element1 element2
geneB element3 element4

It means that for each replicated genes (geneA/geneA), traspose the different element (element1/element2) alongside at the gene.
I have not be able to resolve this issue!!
If someone have any suggestion I will be very grateful.

Thanks

Giuliano
# 2  
Old 06-27-2014
Try
Code:
awk 'T != $NF {T=$NF; printf "%s%s", NL, $NF; NL="\n"} {printf " %s", $2} END {printf NL}' file

This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-27-2014
Code:
# awk '$NF~/gene/{a[$NF]=a[$NF]FS$2}END{for(i in a)print i a[i]}' input
geneA element1 element2
geneB element3 element4

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Transpose the data

Hi All, I have sort of a case to transpose data from rows to column input data Afghanistan|10000|1 Albania|25000|4 Algeria|25000|7 Andorra|10000|4 Angola|25000|47 Antigua and Barbuda|25000|23 Argentina|5000|3 Armenia|100000|12 Aruba|20000|2 Australia|50000|2 I need to transpose... (3 Replies)
Discussion started by: radius
3 Replies

2. UNIX for Dummies Questions & Answers

Transpose File

Have various files like this: InSlot=0x00000001 InPort=0x00000000 Inref=0x0000002f InSID=0x00000001 OutSlot=0x00000001 OutPort=0x00000002 Outref=0x00000000 OutSID=0x0000000b OutUName_2=14 InSlot=0x00000001 InPort=0x00000000 Inref=0x000001a8 InSID=0x00000001 OutSlot=0x00000001... (5 Replies)
Discussion started by: K@rlos
5 Replies

3. Shell Programming and Scripting

Transpose using awk

Hi Friends, Very urgent requirement please do needful ASAP.. Input: |1||1|1||1|3||3|2||2|4||4|2||2|3||3|NA||0|5||5|NA||0|4||4|3||3 output: |1||1 |1||1 |3||3 |2||2 |4||4 |2||2 |3||3 |NA||0 |5||5 (4 Replies)
Discussion started by: bharat1211
4 Replies

4. Shell Programming and Scripting

Transpose Second column only

Hi Folks, My input file is like this cat input abcd:efgh:jklm 123,456,67,78,89,90 hi:kil:op 76,78,12,3456, unix:linux:shell:bash 111,111 My expected output abcd:efgh:jklm hi:kil:op unix:linux:shell:bash 123 76 111 456 78 111 67 12 78 3456 89 90 (5 Replies)
Discussion started by: jacobs.smith
5 Replies

5. Shell Programming and Scripting

Transpose

TRANSPOSE -------------------------------------------------------------------------------- i have a file with recurring fields Start A 1 B 2 C 3 D 4 E 5 End Start A 11 B 12 C 23 D 25 E 21 (1 Reply)
Discussion started by: aravindj80
1 Replies

6. Shell Programming and Scripting

How do I transpose a of results ?

Hello, Can anyone advise me what command I could use to display the results of the following command ATOM 1 ca 2 o 3 h 4 h 5 o dE/dx 0.2057422D-01 0.2463722D-01-0.1068047D-01-0.1495280D-01-0.3725362D-02 dE/dy -0.7179106D-02-0.1554542D-01 0.1016889D-01 0.3268502D-02-0.4888578D-01 dE/dz... (3 Replies)
Discussion started by: wanchem
3 Replies

7. Shell Programming and Scripting

Transpose a file

input IndID ID1 ID2 ID3 a1 a/a b/b c/c a2 a/a b/b c/c a3 a/b b/b c/d a6 a/b b/b c/e a8 a/a b/c c/e a9 b/b b/d c/e output IDName IndID IDtype C_No ID1 a1 a/a 1 ID1 a2 a/a 1 ID1 a8 ... (1 Reply)
Discussion started by: stateperl
1 Replies

8. Shell Programming and Scripting

File Transpose

Hi ALL I have one input file say FILE1 which looks as below. a=1 b=2 c=3 a=4 b=5 c=6 . . . Here a,b,c...etc are variable names. The output file(FILE2) should look like 1,2,3 4,5,6 ..... ..... (5 Replies)
Discussion started by: 46019
5 Replies

9. Shell Programming and Scripting

transpose file

Hi all, I have a file in the below format.... <A> B C <A> E F <A> G H I need the result file to be: <A>BC <A>EF <A>GH (3 Replies)
Discussion started by: new_ds_man
3 Replies

10. Shell Programming and Scripting

Transpose Rows

Hi, Am trying to transpose a set of rows into a set of comma separated values. For eg. if the output of ps -ef | tail +2 | awk 'BEGIN{ FS=" " } { print $2 }' is 0 1 3 4 I need to transpose it to - '0','1','3','4' Am currently trying - (4 Replies)
Discussion started by: iamwha1am
4 Replies
Login or Register to Ask a Question