Adding Leading Zero with Right Justified and Removing Duplicates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding Leading Zero with Right Justified and Removing Duplicates
# 1  
Old 03-18-2009
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  
Old 03-18-2009
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  
Old 03-18-2009
Quote:
Originally Posted by crazyhpux
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  
Old 03-18-2009
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  
Old 03-19-2009
Quote:
Originally Posted by summer_cherry
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  
Old 03-19-2009
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  
Old 03-20-2009
Quote:
Originally Posted by rikxik
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fixed with file- removing leading zeros and adding the space

Hi All, i have a fixed width file , where each line is 3200 length. File: 1ABC 1111 2222 3333 000012341 1001 2ABC 1111 2222 3333 000012342 1002 3ABC 1111 2222 3333 000112343 1003 1DEF 5555 4444 9696 000012344 1004 2DEF 5555 2323 8686 000012345 1005 3DEF 5555 1212 7676 000012346 1006 ... (1 Reply)
Discussion started by: mechvijays
1 Replies

2. Shell Programming and Scripting

Removing leading zeros for a decimal column

removing leading zeros for a decimal column in a file which has string & decimal values ,,,,,6630140,XXXXXXXXXXXXXXX, 0020.00,USA ,,,,,6630150,XXXXXXXXXXXXXXXL (xyz, 0010.00,USA ,,,,,6630150,XXXXXXXXXXXXXXX(xyz), 1300.00,USA My file contains 9 columns. Out 9 columns, 8th column contains the... (9 Replies)
Discussion started by: marpadga18
9 Replies

3. Red Hat

tar: Removing leading `/' from member names

Hello, when i start to take backup following error generate please share solution for this problem i am very thankful to you. $ tar -czvf orahome.tar.gz /testhome/TEST/PROD/orahome/ tar: Removing leading `/' from member names O.S 4.5 Red Hat Thanks, Umair (1 Reply)
Discussion started by: umair
1 Replies

4. Shell Programming and Scripting

Help with adding leading zeros to a filename

Hi i need help in adding leading zero to filenames e.g file name in my folder are 1_234sd.txt 23_234sd.txt the output i need is 001_234sd.txt 023_234sd.txt can i do this shell scripting please help (2 Replies)
Discussion started by: rsmpk
2 Replies

5. Shell Programming and Scripting

sed not removing leading zeroes

I have th following file 0000000011 0000000001 0000000231 0000000001 0000000022 noow when i run the following command sed 's/^0+//g' file name I receive the same output and the leading zeroes are not removed from the file . Please let me know how to achieve... (4 Replies)
Discussion started by: asalman.qazi
4 Replies

6. Shell Programming and Scripting

Removing leading spaces from the variable value.

Hi All, I am trying to replace the value of a xml tag with a new one. But, the existing value in the xml contain leading spaces and I tried to remove that with different sed commands but all in vain. For replacing the value I wrote the command in BOLD letters below: bash-3.00$... (3 Replies)
Discussion started by: khedu
3 Replies

7. Shell Programming and Scripting

Removing leading and trailing spaces only in PERL

Hi All, I have a file with the following contents with multiple lines 172445957| 000005911|8| 400 Peninsula Ave.#1551 | And,K |935172445957|000005911 607573888 |000098536 | 2|Ane, B |J |Ane |1868 |19861206|20090106|20071001 I want to trim the "leading and trailing spaces only" from... (2 Replies)
Discussion started by: kumar04
2 Replies

8. Shell Programming and Scripting

Removing leading zeros from a variable

How do I remove or add leading zeroa from a variable. To make variable 10 characters long when adding zeros. (6 Replies)
Discussion started by: toshidas2000
6 Replies

9. UNIX for Dummies Questions & Answers

removing leading zero

Hi, I do have a code as follows: function deHex { if ]; then deHexDate=${1:1:$2} fi } The description given for the above code is as follows: # description: removes leading zero so value will not be recognized as hex # usage: deHex <value_parameter> <value_input_length> ... (0 Replies)
Discussion started by: risshanth
0 Replies

10. UNIX for Dummies Questions & Answers

Stripping leading spaces on right justified name

I have a name field in a file which is right justified (yep - its true). I need to strip the leading spaces from the field and write the name out left justified. Again, I think I need to use a sed or awk command but so far, my results are at best disappointing. Thank you in advance from a UNIX... (2 Replies)
Discussion started by: Marcia P
2 Replies
Login or Register to Ask a Question