Sponsored Content
Top Forums Shell Programming and Scripting How to delete trailing zeros from a variable Post 302118659 by anbu23 on Wednesday 23rd of May 2007 11:56:07 AM
Old 05-23-2007
Quote:
Originally Posted by Chandu2u
i tried with above solution bt if variable has 1234 den it is returning null bt i want as 1234 it self
Code:
$ echo 1234  | awk ' { sub("\\.*0+$","");print} '
1234

 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Delete trailing white space

I have a string "disk0 with a trailing white space after it" but I want to get rid of this white space from right to left so that I am left with "disk0" only. Using sed 's/ $//g' doesn't seem to work Any ideas ? Thanks (5 Replies)
Discussion started by: cillmor
5 Replies

3. Shell Programming and Scripting

Append zeros before a value as per variable

Hello- I have a variable which contains a number, I need to populate number of zeros before another value as per this variable value. for example: I have variable X whose content is 5, variable Y whose content is 123 Now append number of zeros as per variable X before varible 'Y'... (4 Replies)
Discussion started by: pasupuleti81
4 Replies

4. 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

5. Shell Programming and Scripting

How to delete ending/trailing spaces using awk,sed,perl?

How to delete ending/trailing spaces using awk,sed,perl? Input:(each line has extra spaces at the end) 3456 565 3 7 35 878 Expected output: 3456 565 3 7 35 878 (5 Replies)
Discussion started by: cola
5 Replies

6. Shell Programming and Scripting

tr command to delete zeros

Hi, I have a input string 0000106 I need to extract the number after leading zeros ie the number 106. I used the command tr -d "0" and got the output as 16. Could any one of you please help me in using the tr command to get the output 106. Thanks in advance.... (2 Replies)
Discussion started by: dean_amrita
2 Replies

7. UNIX for Dummies Questions & Answers

delete trailing whitespace from end of each line in column 1 only

Hi All. How can I convert this: ABC_1_1 ABC_1_2 ABC_1_3 into this: ABC_1 1 ABC_1 2 ABC_1 3 I tried this command but it is not working: awk '{sub(/+$/,"\t", $1)}{print}' Any suggestions on how to fix this? Thank you :wall: Please use code tags when posting data and... (3 Replies)
Discussion started by: danieladna
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. UNIX for Beginners Questions & Answers

Remove trailing zeros from numbers

Hi, I am trying to remove trailing zeros from numbers in a csv file. CSV Input : 0.5000,abc,2.00,2.400,285.850,285a.850,205.180800,mno000,a0b0,2.860 Expected Output : .5,abc,2,2.4,285.85,285a.850,205.1808,mno000,a0b0,2.86 Can you please help. Thanks. (11 Replies)
Discussion started by: manubatham20
11 Replies

10. Shell Programming and Scripting

Delete all lines without a trailing semi colon

shell : bash os : RHEL 7.2 I have a file like below 61265388 1-11Y5C-7690 1-11Y4Q-6763 INSERT INTO emp VALUES('oramds:test.xref','CBS_01','MIGWO161265388','61265388','N',SYSDATE); INSERT INTO emp VALUES('oramds:test.xref','COMMON','MIGWO161265388','MIG1COMMON61265388','N',SYSDATE);... (3 Replies)
Discussion started by: kraljic
3 Replies
MONEY_FORMAT(3) 							 1							   MONEY_FORMAT(3)

money_format - Formats a number as a currency string

SYNOPSIS
string money_format (string $format, float $number) DESCRIPTION
money_format(3) returns a formatted version of $number. This function wraps the C library function strfmon(3), with the difference that this implementation converts only one number at a time. PARAMETERS
o $format - The format specification consists of the following sequence: oa % character ooptional flags ooptional field width ooptional left precision ooptional right precision oa required conversion character Flags One or more of the optional flags below can be used: o = f - The character = followed by a (single byte) character f to be used as the numeric fill character. The default fill character is space. o ^ - Disable the use of grouping characters (as defined by the current locale). o + or ( - Specify the formatting style for positive and negative numbers. If + is used, the locale's equivalent for + and - will be used. If ( is used, negative amounts are enclosed in parenthesis. If no specification is given, the default is +. o ! - Suppress the currency symbol from the output string. o - - If present, it will make all fields left-justified (padded to the right), as opposed to the default which is for the fields to be right-justified (padded to the left). Field width o w - A decimal digit string specifying a minimum field width. Field will be right-justified unless the flag - is used. Default value is 0 (zero). Left precision o # n - The maximum number of digits ( n) expected to the left of the decimal character (e.g. the decimal point). It is used usually to keep formatted output aligned in the same columns, using the fill character if the number of dig- its is less than n. If the number of actual digits is bigger than n, then this specification is ignored. If group- ing has not been suppressed using the ^ flag, grouping separators will be inserted before the fill characters (if any) are added. Grouping separators will not be applied to fill characters, even if the fill character is a digit. To ensure alignment, any characters appearing before or after the number in the formatted output such as currency or sign symbols are padded as necessary with space characters to make their positive and negative formats an equal length. Right precision o . p - A period followed by the number of digits ( p) after the decimal character. If the value of p is 0 (zero), the decimal character and the digits to its right will be omitted. If no right precision is included, the default will dictated by the current local in use. The amount being formatted is rounded to the specified number of digits prior to formatting. Conversion characters o i - The number is formatted according to the locale's international currency format (e.g. for the USA locale: USD 1,234.56). o n - The number is formatted according to the locale's national currency format (e.g. for the de_DE locale: EU1.234,56). o % - Returns the % character. o $number - The number to be formatted. RETURN VALUES
Returns the formatted string. Characters before and after the formatting string will be returned unchanged. Non-numeric $number causes returning NULL and emitting E_WARNING. NOTES
Note The function money_format(3) is only defined if the system has strfmon capabilities. For example, Windows does not, so money_for- mat(3) is undefined in Windows. Note The LC_MONETARY category of the locale settings, affects the behavior of this function. Use setlocale(3) to set to the appropriate default locale before using this function. EXAMPLES
Example #1 money_format(3) Example We will use different locales and format specifications to illustrate the use of this function. <?php $number = 1234.56; // let's print the international format for the en_US locale setlocale(LC_MONETARY, 'en_US'); echo money_format('%i', $number) . " "; // USD 1,234.56 // Italian national format with 2 decimals` setlocale(LC_MONETARY, 'it_IT'); echo money_format('%.2n', $number) . " "; // Eu 1.234,56 // Using a negative number $number = -1234.5672; // US national format, using () for negative numbers // and 10 digits for left precision setlocale(LC_MONETARY, 'en_US'); echo money_format('%(#10n', $number) . " "; // ($ 1,234.57) // Similar format as above, adding the use of 2 digits of right // precision and '*' as a fill character echo money_format('%=*(#10.2n', $number) . " "; // ($********1,234.57) // Let's justify to the left, with 14 positions of width, 8 digits of // left precision, 2 of right precision, withouth grouping character // and using the international format for the de_DE locale. setlocale(LC_MONETARY, 'de_DE'); echo money_format('%=*^-14#8.2i', 1234.56) . " "; // Eu 1234,56**** // Let's add some blurb before and after the conversion specification setlocale(LC_MONETARY, 'en_GB'); $fmt = 'The final value is %i (after a 10%% discount)'; echo money_format($fmt, 1234.56) . " "; // The final value is GBP 1,234.56 (after a 10% discount) ?> SEE ALSO
setlocale(3), sscanf(3), sprintf(3), printf(3), number_format(3). PHP Documentation Group MONEY_FORMAT(3)
All times are GMT -4. The time now is 11:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy