Arranging columns in a line | Unix Linux Forums | UNIX for Dummies Questions & Answers

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

Arranging columns in a line

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-08-2013
satyar satyar is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 January 2013, 9:15 AM EST
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
Arranging columns in a line

Hi,
Please give a solution...

Current File


Code:
200101701    A    5    B    283    D    222
200085506    A    5    B    6    C    304
200081406    A    5                    
200101784    D    1111

Desired Output


Code:
200101701    A    0005    B    0283    *    *    D    222    
200085506    A    0005    B    0006    C    0304    *    *
200081406    A    0005    *    *    *    *    *    *
200101784    *    *    *    *    *    *    D    1111

Sorry for formating related issues...

Thank

Last edited by Scrutinizer; 01-08-2013 at 03:54 AM.. Reason: removed img def
Sponsored Links
    #2  
Old 01-08-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 23 November 2014, 8:14 AM EST
Location: Amsterdam
Posts: 9,608
Thanks: 293
Thanked 2,445 Times in 2,193 Posts
What have you tried so far?
Sponsored Links
    #3  
Old 01-08-2013
satyar satyar is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 January 2013, 9:15 AM EST
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
I am trying to solve using awk...
    #4  
Old 01-08-2013
Scrutinizer's Avatar
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 23 November 2014, 8:14 AM EST
Location: Amsterdam
Posts: 9,608
Thanks: 293
Thanked 2,445 Times in 2,193 Posts
What did you try while using awk?
Sponsored Links
    #5  
Old 01-09-2013
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 September 2014, 12:09 PM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
try:

Code:
awk '
BEGIN {str="ABCD"; l=length(str)*2}
{for (i=3; i<=NF; i+=2) $i=sprintf("%04d", $i);
 for (i=2; i<=l; i+=2) {
   j=index(str,$i);
   for (m=i/2; m<j; m++) { $i="*" OFS "*" OFS $i; $0=$0; }
 }
 for (i=(NF-1)/2; i<l/2; i++) { $(NF+i)="*" OFS "*"; }
 $0=$0;
}
$1=$1
' OFS="\t" infile

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
Need Help in arranging the output Sudeep Bhattad Shell Programming and Scripting 4 10-25-2012 04:21 AM
Arranging data bobo UNIX for Dummies Questions & Answers 3 01-20-2012 03:15 PM
arranging columns with AWK sramirez Shell Programming and Scripting 2 12-12-2010 03:06 PM
Averaging 100 columns together line by line jenjen_mt UNIX for Dummies Questions & Answers 2 08-03-2010 02:31 PM
need help in arranging the alias upengan78 Shell Programming and Scripting 4 07-09-2010 05:29 PM



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