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


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-21-2012
Registered User
 
Join Date: May 2012
Posts: 12
Thanks: 3
Thanked 0 Times in 0 Posts
Verticalize lines?

Hi,

I need a way to convert horizontal lines like these

Code:
0101
1010
1100

to vertical lines like these

Code:
0 1 1 
1 0 1
0 1 0
1 0 0

Any help will be much appreciated

Last edited by joeyg; 05-21-2012 at 03:15 PM.. Reason: Please use CodeTags for samples and scripts.
Sponsored Links
    #2  
Old 05-21-2012
neutronscott's Avatar
script kiddie
 
Join Date: Jun 2011
Location: Charleston, SC
Posts: 649
Thanks: 18
Thanked 189 Times in 179 Posts

Code:
#!/usr/bin/awk -f
{
  l=length($0)
  cols=NR
  if (l>rows) rows=l
  for (i=1;i<=l;i++)
    c[i,cols]=substr($0,i,1)
}
END {
  for (i=1;i<=rows;i++)
    for (j=1;j<=cols;j++)
      printf("%s%s", c[i,j], j==cols?"\n":" ")
}


Code:
[mute@geek ~]$ ./script input
0 1 1
1 0 1
0 1 0
1 0 0

Sponsored Links
    #3  
Old 05-21-2012
joeyg's Avatar
joeyg joeyg is online now Forum Staff  
modérateur
 
Join Date: Dec 2007
Location: Out running a Marathon.
Posts: 2,192
Thanks: 48
Thanked 126 Times in 118 Posts
Please remember to search the Boards prior to asking a question

http://www.unix.com/shell-programmin...transpose.html
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search and replace, when found, delete multiple lines, add new set of lines? DeuceLee Shell Programming and Scripting 3 11-23-2011 03:39 PM
In a huge file, Delete duplicate lines leaving unique lines krishnix UNIX for Advanced & Expert Users 16 08-04-2011 04:47 AM
Select lines in which column have value greater than some percent of total file lines vaibhavkorde Shell Programming and Scripting 6 04-21-2011 04:42 AM
How to delete lines in a file that have duplicates or derive the lines that aper once necroman08 Shell Programming and Scripting 3 07-17-2009 05:07 AM
How to count lines - ignoring blank lines and commented lines kthatch UNIX for Dummies Questions & Answers 6 05-25-2007 01:21 AM



All times are GMT -4. The time now is 09:54 AM.