The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
removing duplicates stevie_velvet Shell Programming and Scripting 5 07-07-2008 08:42 AM
removing leading zero risshanth UNIX for Dummies Questions & Answers 0 02-08-2008 06:51 AM
removing duplicates and sort -k orahi001 UNIX for Dummies Questions & Answers 3 01-25-2008 09:59 AM
Stripping leading spaces on right justified name Marcia P UNIX for Dummies Questions & Answers 2 02-28-2006 10:32 PM
Removing duplicates giannicello Shell Programming and Scripting 12 09-14-2005 07:12 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-18-2009
crazyhpux crazyhpux is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 14
Adding Leading Zero with Right Justified and Removing Duplicates

hello everyone. I'm hoping someone can help me out here. I have 2 files. It looks like this:

File 1:

abc1, defg, 50.00, mno,990
abc2, cats, 100.00, pops,991
abc3, dogs, 1.00, treat,992


File 2:

990, airplanes, runway, doctor
991, jets, birds, much
990, *airplanes,runway,doctor
992, cars, ford, toyota

Here is what I would like to do:

1. In file 1, column 3, the amount, i would like it to be right justified with leading zero

2. In file 2, all the duplicate need to be removed. Like 990, *airplanes

3. After file 1 and 2 are done, then join them by using the key in column 5 in file 1 and column 1 in file 2.

If you need more clarification, let me know. I appreciate it greatly if someone can help me out. Thank you.
  #2 (permalink)  
Old 03-18-2009
crazyhpux crazyhpux is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 14
by the way, the final file would be something like this:

abc1, defg, 000050.00, mno ,990, airplanes, runway,doctor
abc2, cats, 000100.00, pops ,991, jets,birds, much
abc3, dogs, 000001.00, treat,992, cars,ford, toyota

for number 3, I would assume use the join command?
  #3 (permalink)  
Old 03-18-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,407
Quote:
Originally Posted by crazyhpux View Post
by the way, the final file would be something like this:

abc1, defg, 000050.00, mno ,990, airplanes, runway,doctor
abc2, cats, 000100.00, pops ,991, jets,birds, much
abc3, dogs, 000001.00, treat,992, cars,ford, toyota

for number 3, I would assume use the join command?
your first file can be arranged in this way

Code:
 
awk -F, '{printf "%s,%s,%09.2f,%s,%s\n",$1,$2,$3,$4,$5}' filename

  #4 (permalink)  
Old 03-18-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,089
Hi, hope below can help you.
But really do not know how many leading '0' you are expecting.


Code:
awk -F"," '{
        if(_[$1]==0){
                _[$1]=1
                print $0
        }
}' a > t1
join -t"," -11 -25 t1 b

  #5 (permalink)  
Old 03-19-2009
crazyhpux crazyhpux is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 14
Quote:
Originally Posted by summer_cherry View Post
Hi, hope below can help you.
But really do not know how many leading '0' you are expecting.


Code:
awk -F"," '{
        if(_[$1]==0){
                _[$1]=1
                print $0
        }
}' a > t1
join -t"," -11 -25 t1 b
thank you for the response so far. The field will be 9 digit. So it will vary on how many zero are place. Trying to make it look like this:

000000000
000000100
000000090
000001100
000012000

The last 2 digit represent the cents. Example 5.50 will be 000000550
  #6 (permalink)  
Old 03-19-2009
rikxik's Avatar
rikxik rikxik is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 250

Code:
awk -F"," '{
        if(_[$1]==0){
                _[$1]=1
                print $0
        }
}' a > t1
join -t"," -11 -25 t1 b | nawk -F"," '$3=sprintf("%011.2f",$3);gsub(/\./,"",$3)'

  #7 (permalink)  
Old 03-20-2009
crazyhpux crazyhpux is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 14
Quote:
Originally Posted by rikxik View Post
Code:
awk -F"," '{
        if(_[$1]==0){
                _[$1]=1
                print $0
        }
}' a > t1
join -t"," -11 -25 t1 b | nawk -F"," '$3=sprintf("%011.2f",$3);gsub(/\./,"",$3)'
would you be so kind to explain the code a bit for me. Thank you for your help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0