Sponsored Content
Top Forums Shell Programming and Scripting how to check string of character Post 302139279 by vino on Friday 5th of October 2007 06:07:04 AM
Old 10-05-2007
Quote:
Originally Posted by manas_ranjan
hey....vino.....
if i could able to solve on my own..i sudn't post it here....
When you face an issue, you show us what you tried, the error that you got and then we would be in a better shape to help you out.

Anyway, this should get you started.

Code:
[/tmp]$ cat try.sh
#! /bin/sh

for sample in abc 123 abc123
do
    if [[ $sample == *[[:alpha:]]* ]] ; then
        echo $sample
    fi;
done
    
[/tmp]$ ./try.sh
abc
abc123
[/tmp]$

I leave the rest to you as an exercise. Look under the section 'Pattern Matching' in the man pages of bash for other character classes.

Last edited by vino; 10-05-2007 at 09:50 AM.. Reason: revised.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

check for the first character to be blank

I'm having a problem when the first line or first character of a file is blank. I need to get rid of both of them when they occur but don't want to delete the line. Does anyone have any suggestions? (7 Replies)
Discussion started by: anthreedhr
7 Replies

2. Programming

converting character string to hex string

HI Hi I have a character string which contains some special characters and I need it to display as a hex string. For example, the sample i/p string: ×¥ïA Å gïÛý and the o/p should be : D7A5EF4100C5010067EFDBFD Any pointers or sample code pls. (5 Replies)
Discussion started by: axes
5 Replies

3. Shell Programming and Scripting

read string, check string length and cut

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. Shell Programming and Scripting

bash script to check the first character in string

Hello would appreciate if somebody can post a bash script that checks if the first character of the given string is equal to, say, "a" thnx in advance (2 Replies)
Discussion started by: ole111
2 Replies

5. AIX

check for a particular character inside a file and substitute with a given character?

i am a newbie to shell script,so i want a kshell script in which i need to check for a particular character inside a file through conditional looping(like if ,case,while)and if that character exists ,then substitute a given character to that character. consider a file test.txt,inside the file... (1 Reply)
Discussion started by: karthikprasathk
1 Replies

6. Shell Programming and Scripting

Korn: How to loop through a string character by character

If I have a string defined as: MyString=abcde echo $MyString How can I loop through it character by character? I haven't been able to find a way to index the string so that I loop through it. shew01 (10 Replies)
Discussion started by: shew01
10 Replies

7. Shell Programming and Scripting

check number of character

hi, I would like to calculate number of character for a number, for exemple : 1200 --> there are 4 characters , 120001 -> 5 characters (4 Replies)
Discussion started by: francis_tom
4 Replies

8. Shell Programming and Scripting

How to check for special character in a value

Hi, I have a variable and to it always alphanumeric value will be assigned. If the value has any special characters in it then in the if statement it should exit like below if (value has any speacial character) then exit else .... fi can any one suggest how to acheive this? (4 Replies)
Discussion started by: lavnayas
4 Replies

9. Shell Programming and Scripting

Check file for string existence before appending it with string

I want to append file with a string but before doing that i want to check if this string already exist in that file.I tried with grep on Solaris 10 but unsuccessful.Man pages from grep seems to suggest if the string is found command status will be 0 and if not 1.But i am not finding it.May be i... (2 Replies)
Discussion started by: sahil_shine
2 Replies

10. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies
ISWALPHA(3)						     Linux Programmer's Manual						       ISWALPHA(3)

NAME
iswalpha - test for alphabetic wide character SYNOPSIS
#include <wctype.h> int iswalpha(wint_t wc); DESCRIPTION
The iswalpha function is the wide-character equivalent of the isalpha function. It tests whether wc is a wide character belonging to the wide character class "alpha". The wide character class "alpha" is a subclass of the wide character class "alnum", and therefore also a subclass of the wide character class "graph" and of the wide character class "print". Being a subclass of the wide character class "print", the wide character class "alpha" is disjoint from the wide character class "cntrl". Being a subclass of the wide character class "graph", the wide character class "alpha" is disjoint from the wide character class "space" and its subclass "blank". Being a subclass of the wide character class "alnum", the wide character class "alpha" is disjoint from the wide character class "punct". The wide character class "alpha" is disjoint from the wide character class "digit". The wide character class "alpha" contains the wide character classes "upper" and "lower". The wide character class "alpha" always contains at least the letters 'A' to 'Z' and 'a' to 'z'. RETURN VALUE
The iswalpha function returns non-zero if wc is a wide character belonging to the wide character class "alpha". Otherwise it returns zero. CONFORMING TO
ISO/ANSI C, UNIX98 SEE ALSO
isalpha(3), iswctype(3) NOTES
The behaviour of iswalpha depends on the LC_CTYPE category of the current locale. GNU
1999-07-25 ISWALPHA(3)
All times are GMT -4. The time now is 07:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy