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

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

Arranging columns in a line

UNIX for Dummies Questions & Answers


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 01-08-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 5 March 2015, 10:59 AM EST
Location: Amsterdam
Posts: 9,961
Thanks: 321
Thanked 2,586 Times in 2,312 Posts
What have you tried so far?
Sponsored Links
    #3  
Old Unix and Linux 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 Unix and Linux 01-08-2013
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 5 March 2015, 10:59 AM EST
Location: Amsterdam
Posts: 9,961
Thanks: 321
Thanked 2,586 Times in 2,312 Posts
What did you try while using awk?
Sponsored Links
    #5  
Old Unix and Linux 01-09-2013
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 13 January 2015, 10:34 AM EST
Location: Houston, Texas, USA
Posts: 681
Thanks: 0
Thanked 206 Times in 198 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 12:01 PM.