Unix/Linux Go Back    


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 !!

Sorting rows to columns

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-13-2013
AAWT AAWT is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 6 June 2013, 5:38 AM EDT
Posts: 37
Thanks: 9
Thanked 0 Times in 0 Posts
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  
Old Unix and Linux 03-13-2013
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 9 July 2015, 10:56 AM EDT
Posts: 1,650
Thanks: 58
Thanked 478 Times in 474 Posts
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  
Old Unix and Linux 03-13-2013
AAWT AAWT is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 6 June 2013, 5:38 AM EDT
Posts: 37
Thanks: 9
Thanked 0 Times in 0 Posts
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.txt

and got, SYNTEX ERROR line 1

waiting for help

Regards
    #4  
Old Unix and Linux 03-13-2013
pamu pamu is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 9 July 2015, 10:56 AM EDT
Posts: 1,650
Thanks: 58
Thanked 478 Times in 474 Posts
Quote:
Originally Posted by AAWT View Post
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.txt

and got, SYNTEX ERROR line 1

waiting for help

Regards
Please give space between awk and filename.

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  
Old Unix and Linux 03-13-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 27 August 2015, 5:17 PM EDT
Location: Aachen, Germany
Posts: 6,572
Thanks: 113
Thanked 1,804 Times in 1,690 Posts
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  
Old Unix and Linux 03-13-2013
AAWT AAWT is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 6 June 2013, 5:38 AM EDT
Posts: 37
Thanks: 9
Thanked 0 Times in 0 Posts
thanks Pamu,
thanks RudiC, its also work fine,
yes, its exactly what I need,Linux
thanks a lot
Regards

Last edited by AAWT; 03-13-2013 at 09:23 AM..
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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



All times are GMT -4. The time now is 03:29 AM.