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
# 8  
Old 03-24-2009
any help on explaining the code for me. Thank you
# 9  
Old 04-07-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)'


I tried that code however it doesn't work...can someone please help me out. Thank you
# 10  
Old 04-07-2009
Quote:
Originally Posted by crazyhpux
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
I thought that it was working for you till the join command. So I just added the nawk part. I think you need to review the awk/join cmd.
# 11  
Old 04-08-2009
i tried

awk -F"," '{
if(_[$1]==0){
_[$1]=1
print $0
}
}' a > t1


with file a and outputting it to t1 however it doesn't do anything. The output file looks the same as the input file.
# 12  
Old 04-08-2009
when I do this code, "awk -F, '{printf "%s,%s,%09.2f,%s,%s\n",$1,$2,$3,$4,$5}' filename"

it actually does output to something I can use however it duplicate it. Example.

File A:

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

running the command:

awk -F"," '$1=sprintf("%s,%s,%011.2f,%s,%s",$1,$2,$3,$4,$5)'

get the following results:

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

how do i not create the duplicate
# 13  
Old 04-13-2009
any help thanks
# 14  
Old 04-13-2009
Try this:

Code:
awk -F, '
NR==FNR{a[$1]=$0;next}
a[$5]{$3=sprintf("%011.2f",$3);$5=a[$5]}1' OFS="," file2 file1

Regards
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