|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
||||
|
||||
|
Please remember to search the Boards prior to asking a question
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|