12-08-2008
numeric string and length
given a string passed to a program that supposed to be numeric and of a certain length say 8 digits - so say for e.g. need to verify this 01234567
How would I parse this string to validat it meet requirements
I tried to use * | sed /\([1-9]\{8})/
Thanks in advance
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have read some figures from a text file by getting the position and wish to do some checking, but it seem like it won't work.
eg. my figure is 0.68 it still go the the else statement,
it seems like it treat it as a text instead of number.
Anybody can Help ? Thanks.
# only... (3 Replies)
Discussion started by: kflee2000
3 Replies
2. Shell Programming and Scripting
Hi guys, I hope you can help me with my problem.
I have a text file that contains lines like this:
78 ANGELO -809.05
79 ANGELO2 -5,000.06
I need to find all occurences of amounts that are negative and replace them with x's
78 ANGELO xxxxxxx
79... (4 Replies)
Discussion started by: amangeles
4 Replies
3. Shell Programming and Scripting
Hello All,
Plz help me with:
I have a csv file with data separated by ',' and optionally enclosed by "". I want to check each of these values to see if they exceed the specified string length, and if they do I want to cut just that value to the max length allowed and keep the csv format as it... (9 Replies)
Discussion started by: ozzy80
9 Replies
4. UNIX for Dummies Questions & Answers
HI
In my script, i am reading the input from the user and want to find the length of the string.
The input may contain leading spaces. Right now, when leading spaces are there, they are not counted.
Kindly help me
My script is like below. I am using the ksh.
#!/usr/bin/ksh
echo... (2 Replies)
Discussion started by: dayamatrix
2 Replies
5. Programming
Hi,
how to check the given string is numeric or not , without converting ( using strtol...).
for ex: if string is C01 - non-numeric data
if string is 001 - numeric data
TIA (11 Replies)
Discussion started by: knowledge_gain
11 Replies
6. Shell Programming and Scripting
I have a customer who logged some cc and bank account numbers in their apache logs. I got the cc numbers x'd out with
sed -e 's/args=\{16\}/args=XXXXXXXXXXXXXXXX/g' -e 's/cardnum=\{16\}/cardnum=XXXXXXXXXXXXXXXX/g'but that wasn't too difficult due to the value being 16 digits.
The bank account... (7 Replies)
Discussion started by: mk4mzid
7 Replies
7. Shell Programming and Scripting
I have a file whose contents are:
$ cat file1
cfd_V03R37
cfd_V03R38
tried
sed 's///g' file1 > file2
$cat file1
0337
0338
Is there any way by which i can work on same file and write o/p to the same file instead of using file2 (3 Replies)
Discussion started by: vjasai
3 Replies
8. Shell Programming and Scripting
hi
i have two types of file
1. temp.0000000001.data (10 digit numeric)
2. temp.000000001.data (9 digit numeric)
i want to search a file which is having 10 digit numeric in between the file name.
i use command like this..
ls | grep temp.^*.data
but this will give both the files as... (2 Replies)
Discussion started by: somi2yoga
2 Replies
9. Shell Programming and Scripting
I checked all the previous threads related to this and tried this.
My input is all numbers or decimals greater than zero everytime.
I want to check the same in the korn shell script.
Just validate the string to be numeric.
This is what I am doing.
var="12345"
if ) -o "$var" !=... (14 Replies)
Discussion started by: megha2525
14 Replies
10. Programming
I have a string
opt="row234"
I want to put "row" in a string and 234 in an int.
In general it should be
opt="textnum"
I want to store text in a string and num in an int. (6 Replies)
Discussion started by: kristinu
6 Replies
LEARN ABOUT PHP
dateinterval.format
DATEINTERVAL.FORMAT(3) 1 DATEINTERVAL.FORMAT(3)
DateInterval::format - Formats the interval
SYNOPSIS
public string DateInterval::format (string $format)
DESCRIPTION
Formats the interval.
PARAMETERS
o $format
-
The following characters are recognized in the $format parameter string. Each format character must be prefixed by a percent sign (
%).
+------------------+--------------------------------------+---+
|$format character | | |
| | | |
| | Description | |
| | | |
| | Example values | |
| | | |
+------------------+--------------------------------------+---+
| | | |
| % | | |
| | | |
| | Literal % | |
| | | |
| | | |
| | % | |
| | | |
| | | |
| Y | | |
| | | |
| | Years, numeric, at least 2 digits | |
| | with leading 0 | |
| | | |
| | | |
| | 01, 03 | |
| | | |
| | | |
| y | | |
| | | |
| | Years, numeric | |
| | | |
| | | |
| | 1, 3 | |
| | | |
| | | |
| M | | |
| | | |
| | Months, numeric, at least 2 digits | |
| | with leading 0 | |
| | | |
| | | |
| | 01, 03, 12 | |
| | | |
| | | |
| m | | |
| | | |
| | Months, numeric | |
| | | |
| | | |
| | 1, 3, 12 | |
| | | |
| | | |
| D | | |
| | | |
| | Days, numeric, at least 2 digits | |
| | with leading 0 | |
| | | |
| | | |
| | 01, 03, 31 | |
| | | |
| | | |
| d | | |
| | | |
| | Days, numeric | |
| | | |
| | | |
| | 1, 3, 31 | |
| | | |
| | | |
| a | | |
| | | |
| | Total number of days as a result of | |
| | a DateTime::diff or (unknown) other- | |
| | wise | |
| | | |
| | | |
| | 4, 18, 8123 | |
| | | |
| | | |
| H | | |
| | | |
| | Hours, numeric, at least 2 digits | |
| | with leading 0 | |
| | | |
| | | |
| | 01, 03, 23 | |
| | | |
| | | |
| h | | |
| | | |
| | Hours, numeric | |
| | | |
| | | |
| | 1, 3, 23 | |
| | | |
| | | |
| I | | |
| | | |
| | Minutes, numeric, at least 2 digits | |
| | with leading 0 | |
| | | |
| | | |
| | 01, 03, 59 | |
| | | |
| | | |
| i | | |
| | | |
| | Minutes, numeric | |
| | | |
| | | |
| | 1, 3, 59 | |
| | | |
| | | |
| S | | |
| | | |
| | Seconds, numeric, at least 2 digits | |
| | with leading 0 | |
| | | |
| | | |
| | 01, 03, 57 | |
| | | |
| | | |
| s | | |
| | | |
| | Seconds, numeric | |
| | | |
| | | |
| | 1, 3, 57 | |
| | | |
| | | |
| R | | |
| | | |
| | Sign " -" when negative, " +" when | |
| | positive | |
| | | |
| | | |
| | -, + | |
| | | |
| | | |
| r | | |
| | | |
| | Sign " -" when negative, empty when | |
| | positive | |
| | | |
| | | |
| | -, | |
| | | |
+------------------+--------------------------------------+---+
RETURN VALUES
Returns the formatted interval.
NOTES
Note
The DateInterval::format method does not recalculate carry over points in time strings nor in date segments. This is expected
because it is not possible to overflow values like "32 days" which could be interpreted as anything from "1 month and 4 days" to "1
month and 1 day".
EXAMPLES
Example #1
DateInterval example
<?php
$interval = new DateInterval('P2Y4DT6H8M');
echo $interval->format('%d days');
?>
The above example will output:
4 days
Example #2
DateInterval and carry over points
<?php
$interval = new DateInterval('P32D');
echo $interval->format('%d days');
?>
The above example will output:
32 days
Example #3
DateInterval and DateTime::diff with the %a and %d modifiers
<?php
$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $february->diff($january);
// %a will output the total number of days.
echo $interval->format('%a total days')."
";
// While %d will only output the number of days not already covered by the
// month.
echo $interval->format('%m month, %d days');
?>
The above example will output:
31 total days
1 month, 0 days
SEE ALSO
DateTime::diff.
PHP Documentation Group DATEINTERVAL.FORMAT(3)