|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sorting rows to columns
Dear all, I need your help to sort out a file with more then 15, 000 rows, input file has following format : Code:
AT4560 GO:1289GO:8915GO:9243GO:5739GO:6757GO:9245GO:9507 output should be like: Code:
AT4560 GO:1289 AT4560 GO:8915 AT4560 GO:9243 AT4560 GO:5739 AT4560 GO:6757 AT4560 GO:9245 AT4560 GO:9507 thanks in advance for help Regards |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
With some assumptions.. Code:
$ awk '{for(i=1;i<=length($2);i+=7){print $1,substr($2,i,7)}}' file
AT4560 GO:1289
AT4560 GO:8915
AT4560 GO:9243
AT4560 GO:5739
AT4560 GO:6757
AT4560 GO:9245
AT4560 GO:9507 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi Pamu, I gave this command in cygwin, Code:
awk '{for(i=1;i<=length($2);i+=7){print $1,substr($2,i,7)}}'AT.txt > ATTT.txtand got, SYNTEX ERROR line 1 waiting for help Regards |
|
#4
|
|||
|
|||
|
Quote:
try with.. Code:
awk '{for(i=1;i<=length($2);i+=7){print $1,substr($2,i,7)}}' AT.txt > ATTT.txt |
| The Following User Says Thank You to pamu For This Useful Post: | ||
AAWT (03-13-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
pamu's proposal works fine if there's always four digit numbers. Should that change, and should "GO" stay the substring where to split the line,try: Code:
$ awk '{gsub (/GO/, FS"GO");for (i=2; i<=NF; i++) print $1, $i}' file
AT4560 GO:1289
AT4560 GO:8915
etc... |
| The Following User Says Thank You to RudiC For This Useful Post: | ||
AAWT (03-13-2013) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
thanks Pamu,
thanks RudiC, its also work fine, yes, its exactly what I need, thanks a lot Regards Last edited by AAWT; 03-13-2013 at 09:23 AM.. |
| 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 |
| Deleting all the fields(columns) from a .csv file if all rows in that columns are blanks | ks_reddy | Shell Programming and Scripting | 4 | 02-04-2013 04:37 AM |
| Kindly Help regarding sorting a file rows | sudiptabhaskar | Shell Programming and Scripting | 2 | 07-25-2012 09:21 AM |
| Sorting by Multiple Columns | theref | UNIX for Dummies Questions & Answers | 2 | 05-18-2012 06:19 AM |
| Sorting by multiple columns | evelibertine | UNIX for Dummies Questions & Answers | 1 | 06-02-2011 09:41 AM |
| sorting of varchar columns | laxmi131 | UNIX for Advanced & Expert Users | 3 | 12-10-2008 07:43 AM |
|
|