Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Remove trailing zeros from numbers Post 302998069 by manubatham20 on Wednesday 24th of May 2017 05:18:27 PM
Old 05-24-2017
Thanks Rudic.

Idea seems nice, it's working fine for the given test case.

Code:
echo 'abc,0.0100' | awk -F, '{for (i=1;i<=NF;i++) {$i = ($i == $i+0)?$i+0:$i}}1' OFS=,

but when I am trying it with quoted strings it's not working.

Code:
echo '"abc","0.0100"' | awk -F, '{for (i=1;i<=NF;i++) {$i=substr($i,2,length($i)-2);$i = ($i == $i+0)?$i+0:$i}}1' OFS=,

Am I doing something wrong?

Thanks,
Manu


Moderator's Comments:
Mod Comment Please use CODE tags correctly as required by forum rules!

Last edited by RudiC; 05-25-2017 at 02:57 AM.. Reason: Changed QUOTE to CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

remove precursing zeros

Hello all, I have a list of reports for stores that are numbered like: s001845,s000022,s198490,s020048,s002385 however the users are displaying the reports as: 1845,22,198490,20048,2385 It isn't real critical but I would like to associate them so they are the same. And since the users are... (2 Replies)
Discussion started by: gozer13
2 Replies

2. Shell Programming and Scripting

Remove O and preceeding zeros in a string

Hi all, Can anybody help me out to write a program in perl to remove O and preceeding zeros. for eg input is O0000123089 - output 123089 Thanks Mahalakshmi.A (10 Replies)
Discussion started by: mahalakshmi
10 Replies

3. Shell Programming and Scripting

Remove trailing G

Hello, I am trying to write a script that will calculate the amount of data remaining in a storage volume. I'm running Tru64 Unix version 5.1B patch kit 6. The script is being run against an AdvFS domain. I am programming in Korn Shell version M-11/16/88f. The basic idea is that I want to run df... (3 Replies)
Discussion started by: Heathe_Kyle
3 Replies

4. Shell Programming and Scripting

How to delete trailing zeros from a variable

Hi All I want to delete trailing zeros from varible. ex: if variable value is 1234.567000 result as 1234.567 if variable has 1234.0000 result as 1234 if variable as abcd.fgh result as abcd.fgh Can somone give me a solution using awk? (16 Replies)
Discussion started by: Chandu2u
16 Replies

5. Shell Programming and Scripting

Removing trailing zeros using sed

Hello All, I have a csv file with 3 columns. The file which looks like this 47850000,100,233 23560000,10000,456 78650000,560000,54 34000000,3456,3 The first column has 4 trailing zeros. I have to remove 4 trailing zeroes from 1st field. The output file should appear as follows. ... (12 Replies)
Discussion started by: grajp002
12 Replies

6. Shell Programming and Scripting

appending zeros to numbers using awk

hi i want to append zeros to a given number ( varying digits). the total length of the output should be 10 digits. For example: 1)input is var=347 output should be NewVar=0000000347 2) input is var=123456 output should be NewVar=0000123456 i am able to acheive this using typeset... (1 Reply)
Discussion started by: somi2yoga
1 Replies

7. Shell Programming and Scripting

Fill missing numbers in second column with zeros

Hi All, I have 100 files with names like this: 1.dat, 2.dat, 3.dat until 100.dat. My dat files look like this: 42323 0 438939 1 434 0 0.9383 3434 120.23 3 234 As you can see in the second column, some numbers are missing. I want to fill those missing places with 0's in all... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

8. Shell Programming and Scripting

Remove trailing zeros

Hi I have a simple request but can't find the answer. I want to remove trailing zeros, and in some cases the fullstops, from the input data. Example of input file: FR002_15.000_20.000 SD475_5.000_10.500 FG5647_12.250_15.500 BH2463_30.555_32.000 Desired output file would be: ... (10 Replies)
Discussion started by: theflamingmoe
10 Replies

9. Shell Programming and Scripting

Numbers with leading zeros

Hi, i have a variable which conatins values like 00001,0003,00067,00459. I want to use the values one by one and in the same form as they are like 00001,0003,00067,00459. Also can anyone tell me how to increment those numbers by 1,keeping the format as same like 00002,0004,00068,00460.... (5 Replies)
Discussion started by: arijitsaha
5 Replies

10. Shell Programming and Scripting

Please help - Command to Subtract two numbers without losing prefix zeros

Hello, I have a variable LOGNUM with values 0000095, When i subtract the variable by 1, Its losing its leading zeros. Can you please help me here ? LOGNUM=0000095 $OLDLOG=`echo "${LOGNUM}-1"|bc` $ echo $OLDLOG 94 Am expecting output as 0000094 Appreciate your help! Thanks,... (11 Replies)
Discussion started by: prince1987
11 Replies
Excel::Template::Container::KeepLeadingZeros(3pm)	User Contributed Perl Documentation	 Excel::Template::Container::KeepLeadingZeros(3pm)

NAME
Excel::Template::Container::KeepLeadingZeros - Excel::Template::Container::KeepLeadingZeros PURPOSE
To set the keep_leading_zeros flag for the surrounding worksheet or any worksheets that might be contained within this node. NODE NAME
KEEP_LEADING_ZEROS INHERITANCE
CONTAINER ATTRIBUTES
None CHILDREN
None EFFECTS
Alters how leading zeros are interpreted by Spreadsheet::WriteExcel. DEPENDENCIES
None USAGE
<worksheet> ... Cells here will NOT have leading-zeros preserved <keep_leading_zeros> ... Cells here will have leading-zeros preserved </keep_leading_zeros> ... Cells here will NOT have leading-zeros preserved </worksheet> <keep_leading_zeros> <worksheet> ... Cells here will have leading-zeros preserved </worksheet> <worksheet> ... Cells here will have leading-zeros preserved </worksheet> </keep_leading_zeros> AUTHOR
Rob Kinyon (rob.kinyon@gmail.com) SEE ALSO
CELL, Spreadsheet::WriteExcel perl v5.14.2 2010-06-17 Excel::Template::Container::KeepLeadingZeros(3pm)
All times are GMT -4. The time now is 07:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy