Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-08-2013
Registered User
 
Join Date: Jan 2013
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 02:54 AM.. Reason: removed img def
Sponsored Links
    #2  
Old 01-08-2013
Scrutinizer's Avatar
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,349
Thanks: 144
Thanked 1,755 Times in 1,592 Posts
What have you tried so far?
Sponsored Links
    #3  
Old 01-08-2013
Registered User
 
Join Date: Jan 2013
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
Moderator
 
Join Date: Nov 2008
Location: Amsterdam
Posts: 7,349
Thanks: 144
Thanked 1,755 Times in 1,592 Posts
What did you try while using awk?
Sponsored Links
    #5  
Old 01-09-2013
Registered User
 
Join Date: Sep 2012
Location: Houston, Texas, USA
Posts: 571
Thanks: 0
Thanked 173 Times in 167 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
Reply

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



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