How do I transpose a of results ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I transpose a of results ?
# 1  
Old 05-07-2010
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

Code:
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 -0.5600872D-02 0.3110649D-01-0.4088230D-02-0.2295107D-01-0.2832048D-01
ATOM 6 h 7 h 8 o 9 h 10 h
dE/dx 0.9525615D-02-0.9503037D-02 0.1689507D-01 0.7277895D-03-0.2111557D-01
dE/dy 0.3902392D-01 0.1220264D-01 0.5837539D-01-0.1350591D-02-0.6110345D-01
dE/dz 0.2086767D-01 0.1308971D-01 0.4212211D-01-0.3857783D-02-0.3506507D-01
ATOM 11 o 12 h 13 h 14 o 15 h
dE/dx -0.1542481D-01 0.9872019D-02-0.2025238D-02 0.6888561D-02 0.1057477D-01
dE/dy -0.1334465D-01 0.3666496D-02 0.1088555D-01 0.2137170D-01-0.6013097D-02
dE/dz 0.2977948D-01-0.1278534D-01-0.1272541D-01 0.4976557D-02-0.5361850D-03
ATOM 16 h 17 o 18 h 19 h 20 o
dE/dx -0.1607803D-01-0.4466439D-02-0.8633477D-02 0.1463235D-01-0.1256357D-01
dE/dy -0.1357829D-01-0.2266521D-01 0.4109669D-01-0.4789354D-02-0.3342545D-01
dE/dz -0.6053460D-02-0.3893747D-02-0.1146559D-01 0.1447851D-01 0.2771696D-01
ATOM 21 h 22 h 23 o 24 h 25 h
dE/dx 0.1159822D-02 0.6070351D-02 0.8284857D-02-0.6641931D-03-0.1313546D-01
dE/dy 0.1192183D-01 0.1009477D-01-0.5001876D-02-0.2469536D-02 0.1214988D-01
dE/dz -0.3776217D-01 0.4180746D-02 0.5491223D-02 0.2433015D-02-0.8376573D-02
ATOM 26 o 27 h 28 h 29 o 30 h
dE/dx 0.1103057D-01-0.1328518D-01 0.9606614D-02 0.3365380D-02 0.4944141D-02
dE/dy -0.1885375D-01 0.2136716D-01-0.2015923D-03 0.1388877D-01-0.5653677D-02
dE/dz 0.2716471D-01-0.3088887D-01-0.2871229D-02-0.8382806D-03 0.3075100D-02
ATOM 31 h
dE/dx -0.1252600D-01
dE/dy -0.8830054D-02
dE/dz 0.1604802D-02

Like this
Code:
Atom dE/dx dE/dy dE/dz
1 ca 0.2057422D-01 -0.7179106D-02 -0.5600872D-02 
2 o 0.2463722D-01 -0.1554542D-01 0.3110649D-01
3 h -0.1068047D-01 0.1016889D-01 -0.4088230D-02
etc

Thank you
Wan

---------- Post updated at 02:53 AM ---------- Previous update was at 02:43 AM ----------

I mean from ....
Code:
 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 -0.5600872D-02 0.3110649D-01-0.4088230D-02-0.2295107D-01-0.2832048D-01

to....
Code:
Atom      dE/dx                     dE/dy                     dE/dz
1 ca      0.2057422D-01       -0.7179106D-02       -0.5600872D-02 
etc.

by using awk commands
thanks

edit by scottn: Use [code][/code] tags please!

Last edited by Scott; 05-07-2010 at 04:59 AM.. Reason: Removed formatting, added code tags
# 2  
Old 05-07-2010
Try and adapt the following AWK program :
Code:
awk '

BEGIN {
   id1 = "Id1";
   id2 = "Id2";
    dx = "dE/dx";
    dy = "dE/dy";
    dz = "dE/dz";
   pattern_dE = "^dE\\/d[xyz]";
}

function printAtom() {
   if (atomCount != 0) {
      print "Atom dE/dx dE/dy dE/dz";
      for (i=1; i<=atomCount; i++) {
         print atom[i, id1], atom[i, id2], atom[i, dx], atom[i, dy], atom[i, dz];
      }
      atomCount = 0;
   }
}

{ gsub(/D-[^ -]*/, "& ") }

/^ATOM/ {
   printAtom();

   atomCount = (NF - 1) / 2;
   for (i=1; i<=atomCount; i++) {
      atom[i, id1] = $(i*2);
      atom[i, id2] = $(i*2+1);
   }
}

$0 ~ pattern_dE {
   for (i=1; i<=atomCount; i++) {
      atom[i, $1] = $(i+1);
   }
}

END {
   printAtom();
}

' wan.txt

Output :
Code:
Atom dE/dx dE/dy dE/dz
1 ca 0.2057422D-01 -0.7179106D-02 -0.5600872D-02
2 o 0.2463722D-01 -0.1554542D-01 0.3110649D-01
3 h -0.1068047D-01 0.1016889D-01 -0.4088230D-02
4 h -0.1495280D-01 0.3268502D-02 -0.2295107D-01
5 o -0.3725362D-02 -0.4888578D-01 -0.2832048D-01
Atom dE/dx dE/dy dE/dz
6 h 0.9525615D-02 0.3902392D-01 0.2086767D-01
7 h -0.9503037D-02 0.1220264D-01 0.1308971D-01
8 o 0.1689507D-01 0.5837539D-01 0.4212211D-01
9 h 0.7277895D-03 -0.1350591D-02 -0.3857783D-02
10 h -0.2111557D-01 -0.6110345D-01 -0.3506507D-01
Atom dE/dx dE/dy dE/dz
11 o -0.1542481D-01 -0.1334465D-01 0.2977948D-01
12 h 0.9872019D-02 0.3666496D-02 -0.1278534D-01
13 h -0.2025238D-02 0.1088555D-01 -0.1272541D-01
14 o 0.6888561D-02 0.2137170D-01 0.4976557D-02
15 h 0.1057477D-01 -0.6013097D-02 -0.5361850D-03
Atom dE/dx dE/dy dE/dz
16 h -0.1607803D-01 -0.1357829D-01 -0.6053460D-02
17 o -0.4466439D-02 -0.2266521D-01 -0.3893747D-02
18 h -0.8633477D-02 0.4109669D-01 -0.1146559D-01
19 h 0.1463235D-01 -0.4789354D-02 0.1447851D-01
20 o -0.1256357D-01 -0.3342545D-01 0.2771696D-01
Atom dE/dx dE/dy dE/dz
21 h 0.1159822D-02 0.1192183D-01 -0.3776217D-01
22 h 0.6070351D-02 0.1009477D-01 0.4180746D-02
23 o 0.8284857D-02 -0.5001876D-02 0.5491223D-02
24 h -0.6641931D-03 -0.2469536D-02 0.2433015D-02
25 h -0.1313546D-01 0.1214988D-01 -0.8376573D-02
Atom dE/dx dE/dy dE/dz
26 o 0.1103057D-01 -0.1885375D-01 0.2716471D-01
27 h -0.1328518D-01 0.2136716D-01 -0.3088887D-01
28 h 0.9606614D-02 -0.2015923D-03 -0.2871229D-02
29 o 0.3365380D-02 0.1388877D-01 -0.8382806D-03
30 h 0.4944141D-02 -0.5653677D-02 0.3075100D-02
Atom dE/dx dE/dy dE/dz
31 h -0.1252600D-01 -0.8830054D-02 0.1604802D-02

Jean-Pierre.
# 3  
Old 05-07-2010
thank you very much but if i want only

Code:
1 ca 0.2057422D-01 -0.7179106D-02 -0.5600872D-02
2 o 0.2463722D-01 -0.1554542D-01 0.3110649D-01
3 h -0.1068047D-01 0.1016889D-01 -0.4088230D-02
4 h -0.1495280D-01 0.3268502D-02 -0.2295107D-01
5 o -0.3725362D-02 -0.4888578D-01 -0.2832048D-01
.
.
.
31 h -0.1252600D-01 -0.8830054D-02 0.1604802D-02

How can I adapt this program?
thank you
wan

Last edited by Scott; 05-07-2010 at 06:30 AM.. Reason: Code tags, PLEASE!
# 4  
Old 05-07-2010
Quote:
Originally Posted by wanchem
thank you very much but if i want only

Code:
1 ca 0.2057422D-01 -0.7179106D-02 -0.5600872D-02
2 o 0.2463722D-01 -0.1554542D-01 0.3110649D-01
3 h -0.1068047D-01 0.1016889D-01 -0.4088230D-02
4 h -0.1495280D-01 0.3268502D-02 -0.2295107D-01
5 o -0.3725362D-02 -0.4888578D-01 -0.2832048D-01
.
.
.
31 h -0.1252600D-01 -0.8830054D-02 0.1604802D-02

How can I adapt this program?
thank you
wan
Remove the red line from the printAtom unction :
Code:
function printAtom() {
   if (atomCount != 0) {
      print "Atom dE/dx dE/dy dE/dz";
      for (i=1; i<=atomCount; i++) {
         print atom[i, id1], atom[i, id2], atom[i, dx], atom[i, dy], atom[i, dz];
      }
      atomCount = 0;
   }
}

Jean-Pierre.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to add a variable for the results from the formula of one variable and results of another var

Good morning all, This is the file name in question OD_Orders_2019-02-19.csv I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

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): factor1 element1 chr1 309343146 330945480 1 protein_coding geneA factor2 element2 chr2 309350853 309603230 1 protein_coding geneA factor3 element3 chr3... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

6. 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

7. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

8. 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

9. Shell Programming and Scripting

How do I transpose a column of results to a row

Hi, Can anyone advise me what command I could use to display the results of the following command as a row. Thanks Gareth (6 Replies)
Discussion started by: m223464
6 Replies

10. UNIX for Dummies Questions & Answers

transpose command

I need to transpose data from one row to one column. If there is any idea to do it would be helpful. example of input data 314.16177368164102, 314.71533203125, 315.208740234375 wantted output data 314.16177368164102 314.71533203125 315.208740234375 Thank you so much for any advance... (3 Replies)
Discussion started by: su_in99
3 Replies
Login or Register to Ask a Question