Sponsored Content
Top Forums Shell Programming and Scripting Converting String To Integer/Float (weird case) Post 302989288 by sekfarok on Tuesday 10th of January 2017 10:58:13 PM
Old 01-10-2017
Quote:
Originally Posted by RudiC
Try
Code:
awk '{X = substr ($1,7,9); sub (/^0+/, "", X); print X}' file
234
-123
234
234
-11234
234
234

Thank you so much. tested your solutions and it works. all my calculations are correct too now SmilieSmilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Integer/Float Script Problem

Hi, I have a script which takes a value from a file and performs calculations on it. Trouble is that this value is a float not an integer and it errors at the decimal point! eg. 94.62 I would like to be able to detect the length of the float (in this above case, 5 characters), and simply do a... (2 Replies)
Discussion started by: danhodges99
2 Replies

2. Shell Programming and Scripting

command for converting string to integer

Hi ... I am trying to calculate the time needed for a command to execute.. but the resulting value is getting as string.. so i am not able to use "expr " command.. please help me to convert the value to integer so that i can proceed with my script.. Regards esham (1 Reply)
Discussion started by: esham
1 Replies

3. Shell Programming and Scripting

Converting the case of the string?

Hi i have a string value in a variable STR eg. STR="ABSDSCSFS" How can be convert it to LOWERCASE in the script? Thanks (5 Replies)
Discussion started by: skyineyes
5 Replies

4. UNIX for Dummies Questions & Answers

Converting a String variable into Integer

Hi, I am passing a variable to a unix function. However when I try to assign the value to another variable like typeset -i I_CACHE_VAL=$2 Is this because of String to Integer conversion? I get an error. Please help me with thsi. Thanks (2 Replies)
Discussion started by: neeto
2 Replies

5. Shell Programming and Scripting

Converting integer to String

Hi everyone, I would like to know how to convert an integer to a string. for instance if i=1 i would like to creat a variable called constant1. i want to do this in a for loop so for each value of i, i create a new variable such as constant2, constant3,... and so on. for i in 1 2 3 do ... (1 Reply)
Discussion started by: ROOZ
1 Replies

6. UNIX for Advanced & Expert Users

byte swapping 32-bit float and weird od results

I'm attempting to read a file that is composed of complex 32-bit floating point values on Solaris 10 that came from a 64-bit Red Hat computer. When I first tried reading the file, it looked like there was a byte-swapping problem and after running the od command on the file Solaris and Red Hat... (2 Replies)
Discussion started by: GoDonkeys
2 Replies

7. Shell Programming and Scripting

converting to lower case or upper case

here is a code column_name="vivek" column_name2="ViVeK" column_name=$(echo $column_name | awk '{print tolower($0)}') column_name2=$(echo $column_name2 | awk '{print tolower($0)}') echo "column name 1 lower: $column_name" echo "column name... (6 Replies)
Discussion started by: vivek d r
6 Replies

8. Shell Programming and Scripting

Converting Month into Integer

okay so i run an openssl command to get the date of an expired script. Doing so gives me this: enddate=Jun 26 23:59:59 2012 GMT Then i cut everything out and just leave the month which is "Jun" Now the next part of my script is to tell the user if the the certificate is expired or not... (6 Replies)
Discussion started by: shade917
6 Replies

9. Shell Programming and Scripting

Converting date +%j into integer

Dear community, i got a problem to get "date +%j" as the right value. Today is the 10th day of the year. #./script.sh 2 #!/bin/bash/ Var1=$(date +%j) Var2=$1 let result=$Var1+$Var2 echo $Var1 plus $Var2 equals $result The output of the script is: 010 plus 2 equals 10... (9 Replies)
Discussion started by: OskarHF
9 Replies

10. Shell Programming and Scripting

Converting string to integer

I have a function that is supposed to check for user processes and wait for 0 count before exiting the function. I am sure I have more than one issue in my code, but the stumbling block right now is that I am trying to convert the value of my variable from a string to integer. process_count... (10 Replies)
Discussion started by: MIA651
10 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 08:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy