Sponsored Content
Full Discussion: Number/string format in bash
Top Forums Shell Programming and Scripting Number/string format in bash Post 302307855 by josegr on Thursday 16th of April 2009 01:06:22 PM
Old 04-16-2009
thanks:
printf "%06d\n"
can it be done with echo as well?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to format number/string in ksh

Hi, How to format a number in ksh. For example x=RANDOM $$ I want x to be of 20 digits long, so if x = 12345 I want it to be left paded with 15 zeros. Thanks. (2 Replies)
Discussion started by: GNMIKE
2 Replies

2. Shell Programming and Scripting

bash: testing if string is a number

How do you test if a string is a number? Trying to do something like this: x="AS" if( x is not a number ); then x=0 fi Because I want to do number arithmetic with x. (3 Replies)
Discussion started by: eur0dad
3 Replies

3. Shell Programming and Scripting

number format in Perl

I try to read in a file and write out a new file with increased number at the end of each line. And I can set the initial value and increased constant from inputs. input file: text1 text2 text3 ... text100 if I set initial value is 10, and increased constant is 0.4 output file: text1... (3 Replies)
Discussion started by: jinsh
3 Replies

4. Shell Programming and Scripting

Need to change format of number

Hi, using a shell script to get values from a CSV eg: 12345.67,5678990.89,76232882.90 12345,5678990.89,76232882 Need the format of these numbers to change to 12,345.67:5,678,990.89:76,232,882.90 12,345:5678990.89:76232882 Using nawk on solaris, to parse these values, need the... (10 Replies)
Discussion started by: pgop
10 Replies

5. Shell Programming and Scripting

how to format a number in bash

Say I have a number x=123, but I want to it be x=000123, because I need to use it in as a file name. thanks! (2 Replies)
Discussion started by: aerosols
2 Replies

6. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

7. Shell Programming and Scripting

How to format string/date in bash?

I have string like "1-JUN-11" and it needs to be converted to "01JUN11" and "1/6/2011":confused::confused::confused: Thanks (2 Replies)
Discussion started by: ford99
2 Replies

8. Shell Programming and Scripting

Bash script accepting variables in valid number format

Hi Experts I would like to ask if there is a way to validate if the variable passed is in this kind of sample format "06-10" or "10-01". It was really a challenge to me on how to start and echnically the "6-10" stands for "June 10" and "10-01" stands as "October 1", overall it needs to have ... (3 Replies)
Discussion started by: ersan-poguita
3 Replies

9. UNIX for Beginners Questions & Answers

Escape bash-special character in a bash string

Hi, I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user... (5 Replies)
Discussion started by: arcoa05
5 Replies

10. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies
IP2LONG(3)								 1								IP2LONG(3)

ip2long - Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address

SYNOPSIS
int ip2long (string $ip_address) DESCRIPTION
The function ip2long(3) generates an IPv4 Internet network address from its Internet standard format (dotted string) representation. ip2long(3) will also work with non-complete IP addresses. Read http://publibn.boul- der.ibm.com/doc_link/en_US/a_doc_lib/libs/commtrf2/inet_addr.htm for more info. PARAMETERS
o $ip_address - A standard format address. RETURN VALUES
Returns the IPv4 address or FALSE if $ip_address is invalid. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ |5.2.10 | | | | | | | Prior to this version, ip2long(3) would some- | | | times return a valid number even if passed an | | | value which was not an (IPv4) Internet Protocol | | | dotted address. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 ip2long(3) Example <?php $ip = gethostbyname('www.example.com'); $out = "The following URLs are equivalent:<br /> "; $out .= 'http://www.example.com/, http://' . $ip . '/, and http://' . sprintf("%u", ip2long($ip)) . "/<br /> "; echo $out; ?> Example #2 Displaying an IP address This second example shows how to print a converted address with the printf(3) function in both PHP 4 and PHP 5: <?php $ip = gethostbyname('www.example.com'); $long = ip2long($ip); if ($long == -1 || $long === FALSE) { echo 'Invalid IP, please try again'; } else { echo $ip . " "; // 192.0.34.166 echo $long . " "; // -1073732954 printf("%u ", ip2long($ip)); // 3221234342 } ?> NOTES
Note Because PHP's integer type is signed, and many IP addresses will result in negative integers on 32-bit architectures, you need to use the "%u" formatter of sprintf(3) or printf(3) to get the string representation of the unsigned IP address. Note ip2long(3) will return FALSE for the IP 255.255.255.255 in PHP 5 <= 5.0.2. It was fixed in PHP 5.0.3 where it returns -1 (same as PHP 4). SEE ALSO
long2ip(3), sprintf(3). PHP Documentation Group IP2LONG(3)
All times are GMT -4. The time now is 07:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy