Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Ksh Checking if string has 2 characters and does not contain digits? Post 302183249 by era on Tuesday 8th of April 2008 03:19:04 PM
Old 04-08-2008
Code:
case $string in
  *[0-9]*) echo ouch, numbers >&2;
      implode --fatally; meditate --guru; exit 127;;
  ??) echo exactly two characters, what joy;;
  *) echo ouch, not exactly two characters >&2;
      burn --stake --confessions; inquisition --spanish; reboot -h now;;
esac

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

to check if a string has only digits

Hi guys, I am not very experienced in writing ksh scripts and I am trying to write a piece of code that indicates if a given string contains only digits and no alphabet (upper or lower case). If i write it my way it would turn out to have a lot of comparisons.. :eek: Thanks a lot in... (3 Replies)
Discussion started by: lakshmikanth
3 Replies

2. Shell Programming and Scripting

Extract digits at end of string

I have a string like xxxxxx44. What's the best way to extract the digits (one or more) in a ksh script? Thanks (6 Replies)
Discussion started by: offirc
6 Replies

3. UNIX for Dummies Questions & Answers

ksh Checking if variable has 5 digits

How could I check if a numeric variable has 5 digits in KSH...I have a zipcode variable that I know will always be 5 digits, and I want to print out an error if it is less or more than 5 digits the problem is that I have it as: if ] but this won't work because the statement doesn't see 0001 as... (3 Replies)
Discussion started by: developncode
3 Replies

4. Shell Programming and Scripting

find the last digits of a string

print out 201 in following string, Please note the chars before 201 are random, no fixed format. ua07app201 (20 Replies)
Discussion started by: honglus
20 Replies

5. Shell Programming and Scripting

extract digits from a string in unix

Hi all, i have such string stored in a variable var1 = 00000120 i want the o/p var1 = 120 is it possible to have such o/p in ksh/bash ... thanx in advance for the help sonu (3 Replies)
Discussion started by: sonu_pal
3 Replies

6. UNIX for Dummies Questions & Answers

locate special characters and digits using grep

Hello, i have a file called test hello1 "how" are you4 good"bye" good7bye i am trying to print all lines from test that either end with a digit or contain a double quote character anywhere on the line. i did grep -n '$' test and was able to print lines ending with digits. i also did... (2 Replies)
Discussion started by: hobiwhenuknowme
2 Replies

7. Shell Programming and Scripting

awk search between 2 digits a string

I would like to search between two a string. I thought this would be easy. The is always at the beginning of a line. The code: gawk '/^/{d=$1},/searchstring/,/^(d+1)/' or gawk '/^/,/searchstring/,/^/' did not return the desired result. inputfile.txt 999 some text searchstring some... (6 Replies)
Discussion started by: sdf
6 Replies

8. Shell Programming and Scripting

ksh check for non printable characters in a string

Hi All, I am trying to find non-printable characters in a string. The sting could have alphanumeric, puntuations and characters like (*&%$#.') but not non-printable (or that is what I think they are called) which are introduced when you copy any text from DOS to unix box. Input string1:... (10 Replies)
Discussion started by: dips_ag
10 Replies

9. Shell Programming and Scripting

Extract n-digits from string in perl

Hello, I have a log file with logs such as 01/05/2017 10:23:41 : file.log.38: database error, MODE=SINGLE, LEVEL=critical, STATE: 01170255 (mode main how can i use perl to extract the 8-digit number below from the string 01170255 Thanks (7 Replies)
Discussion started by: james2009
7 Replies

10. Shell Programming and Scripting

Random Password generator with 2 digits and 6 characters

I am using the below to random generate a password but I need to have 2 numeric characters and 6 alphabetic chars head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8 ; echo '' 6USUvqRB ------ Post updated at 04:43 PM ------ Any Help folks - Can the output be passed onto a sed command to... (9 Replies)
Discussion started by: infernalhell
9 Replies
CTYPE_DIGIT(3)								 1							    CTYPE_DIGIT(3)

ctype_digit - Check for numeric character(s)

SYNOPSIS
bool ctype_digit (string $text) DESCRIPTION
Checks if all of the characters in the provided string, $text, are numerical. PARAMETERS
o $text - The tested string. RETURN VALUES
Returns TRUE if every character in the string $text is a decimal digit, FALSE otherwise. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.1.0 | | | | | | | Before PHP 5.1.0, this function returned TRUE | | | when $text was an empty string. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A ctype_digit(3) example <?php $strings = array('1820.20', '10002', 'wsl!12'); foreach ($strings as $testcase) { if (ctype_digit($testcase)) { echo "The string $testcase consists of all digits. "; } else { echo "The string $testcase does not consist of all digits. "; } } ?> The above example will output: The string 1820.20 does not consist of all digits. The string 10002 consists of all digits. The string wsl!12 does not consist of all digits. Example #2 A ctype_digit(3) example comparing strings with integers <?php $numeric_string = '42'; $integer = 42; ctype_digit($numeric_string); // true ctype_digit($integer); // false (ASCII 42 is the * character) is_numeric($numeric_string); // true is_numeric($integer); // true ?> NOTES
Note This function expects a string to be useful, so for example passing in an integer may not return the expected result. However, also note that HTML forms will result in numeric strings and not integers. See also the types section of the manual. Note If an integer between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character (negative val- ues have 256 added in order to allow characters in the Extended ASCII range). Any other integer is interpreted as a string contain- ing the decimal digits of the integer. SEE ALSO
ctype_alnum(3), ctype_xdigit(3), is_numeric(3), is_int(3), is_string(3). PHP Documentation Group CTYPE_DIGIT(3)
All times are GMT -4. The time now is 01:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy