The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
More than transposing! bulash UNIX Desktop for Dummies Questions & Answers 3 04-11-2008 02:20 PM
Transposing string unibboy Shell Programming and Scripting 3 02-13-2008 03:12 PM
Major Awk problems (Searching, If statements, transposing etc.) Blivo Shell Programming and Scripting 2 09-05-2007 03:41 AM
Another transposing issue stevesmith Shell Programming and Scripting 14 09-16-2006 01:48 AM
transposing letters myscsa2004 Shell Programming and Scripting 4 05-12-2004 07:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-19-2005
Registered User
 

Join Date: Jul 2005
Posts: 37
file transposing

Hello,

Is there a way to transpose a file in shell scripting? For instance, from

a1 a2 a3 a4 a5 a6 a7 ....
b1 b2 b3 b4 b5 b6 b7 ....
c1 c2 c3 c4 c5 c6 c7 ....
d1 d2 d3 d4 d5 d6 d7 ...
...
...
...

to

a1 b1 c1 d1 ....
a2 b2 c2 d2 ....
a3 b3 c3 d3 ....
a4 b3 c3 d4 ....
...
...
...

Thanks in advance.
Reply With Quote
Forum Sponsor
  #2  
Old 07-19-2005
reborg's Avatar
Administrator
 

Join Date: Mar 2005
Location: Ireland
Posts: 3,642
Yes there is, the question has been answered here several times. Try using the search functionality with keywords "row", "column" and "transpose".
Reply With Quote
  #3  
Old 07-19-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Try...
Code:
awk '{
      for (f = 1; f <= NF; f++)
         a[NR, f] = $f
   }
   NF > nf { nf = NF }
   END {
      for (f = 1; f <= nf; f++)
         for (r = 1; r <= NR; r++)
            printf a[r, f] (r==NR ? RS : FS)
   }' file1 > file2
Reply With Quote
  #4  
Old 07-29-2005
Registered User
 

Join Date: Jul 2005
Posts: 37
Thanks, but the code didn't work. Any idea? why
Reply With Quote
  #5  
Old 07-29-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,022
no, not from your description - works fine here.
Reply With Quote
  #6  
Old 07-29-2005
Registered User
 

Join Date: Jul 2005
Posts: 37
Wired, My file is a multi-column based tab delimited file with uneven rows. It needs to be transposed to row based txt file. This is code,
bash-2.03$ more file_transpose
###file transpose, colume to row
###from unix.com/ygor, 07/29/2005

awk '{
for (f = 1; f <= NF; f++)
a[NR, f] = $f
}
NF > nf { nf = NF }
END {
for (f = 1; f <= nf; f++)
for (r = 1; r <= NR; r++)
printf a[r, f] (r==NR ? RS : FS)
}' atcc_fidler_pvs_all_markers.txt > atcc_fidler_pvs_all_markers_out.txt

The error message is,
sorgerlab-x% bash
bash-2.03$ ./file_transpose
awk: syntax error near line 3
awk: illegal statement near line 3
awk: syntax error near line 9
awk: illegal statement near line 9

Thanks for the help
Reply With Quote
  #7  
Old 07-29-2005
Registered User
 

Join Date: Jul 2005
Posts: 37
by the way, how to search the archives here.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0