Sponsored Content
Full Discussion: grep and alphanumerics
Top Forums Shell Programming and Scripting grep and alphanumerics Post 302722613 by Don Cragun on Sunday 28th of October 2012 03:44:23 AM
Old 10-28-2012
Quote:
Originally Posted by maverick_here
Have you gone through all my posts before coming to a conclusion.Please understand the question and then try to answer. Anyways, I figured out a solution my self.
Dear maverick_here,
Maybe you should go back and reread your posts. The title of this thread is grep and alphanumerics, not grep alphabetics and numerics. I pointed out that the RE you were using was matching and printing any line that contained any one of the characters ':', 'a', 'l', 'n', 'u', or 'm' rather than any alphanumeric character. You responded that the RE I suggested [[:alnum:]] also printed the lines:
Code:
data
sample data

and said that they are only lower case (which is not true since' 'is not a lowercase letter) and shouldn't matter since you said you wanted to match alphanumeric characters (and lowercase letters are alphanumeric characters).

The RE that you say works: [a-z][0-9]|[0-9][a-z], is not looking for an alphanumeric character; it is an ERE looking for a lowercase letter immediately followed by a decimal digit or a decimal digit immediately followed by a lowercase letter assuming that you are using a locale that is using a codeset that is a superset of ASCII. (But, since you used grep's -i option, grep will ignore case when looking for alphabetic characters.) If you are using an EBCDIC codeset, [a-z] will also match several characters that are not lowercase alphabetics, and if you are in a locale in which alphabetic characters includes letters with accents, [a-z] will not find the accented letters. If you had said that you wanted a portable ERE that would match a lowercase letter adjacent to a digit in the current locale in either order or an ERE that would match any letter adjacent to a digit in the current locale, I would have suggested:
Code:
grep -E '[[:lower:]][[:digit:]]|[[:digit:]][[:lower:]]' regexp

or
Code:
grep -E '[[:alpha:]][[:digit:]]|[[:digit:]][[:alpha:]]' regexp

respectively, but you never requested that.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use non alphanumerics in join

Hi, I have a problem while joining two sorted files with "join". File 1.txt Alnus|123 ALO140102|234 ALO 1401 02|345 ALO-1401-02|456 Alobar Holoprosencephalies|567 File 2.txt 1|Alnus| 1|ALO 1401 02| 1|ALO-1401-02| 1|Alobar Holoprosencephalies| If I join the files as follows:... (1 Reply)
Discussion started by: s0460205
1 Replies

2. Shell Programming and Scripting

Strip all non-alphanumerics

Hi, Can someone let me know how do I strip out any non-alphanumeric character in string tomake it alphanumeric? i.e abc def ghi ->abcdefghi abc-def-ghi ->abcdefghi abc#def-ghi->abcdefghi Thanks in advance (3 Replies)
Discussion started by: braindrain
3 Replies

3. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies

4. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

5. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

6. Shell Programming and Scripting

How to filter Alphanumerics

Hi all, Can you please let me know how to achieve the below thing AAABBCC@#$W123 123@#$DFG<>. Output: AAABBCW123 123DFG i.e I want to filer only alphanumerics from the strings (4 Replies)
Discussion started by: marcus_kosaman
4 Replies

7. UNIX for Dummies Questions & Answers

Advanced grep'in... grep for data next to static element.

I have a directory I need to grep which consists of numbered sub directories. The sub directory names change daily. A file resides in this main directory that shows which sub directories are FULL backups or INCREMENTAL backups. My goal is to grep the directory for the word "full" and then... (2 Replies)
Discussion started by: SysAdm2
2 Replies

8. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

9. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

10. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies
wctype(3C)																wctype(3C)

NAME
wctype(), iswalpha(), iswblank(), iswupper(), iswlower(), iswdigit(), iswxdigit(), iswalnum(), iswspace(), iswpunct(), iswprint(), isw- graph(), iswcntrl(), iswctype() - classify wide characters SYNOPSIS
Remarks These functions are compliant with the XPG4 Worldwide Portability Interface wide-character classification functions. They parallel the 8-bit character classification functions defined in ctype(3C). DESCRIPTION
These functions classify wide character values according to the rules of the coded character set identified by the last successful call to (see setlocale(3C)). If has not been called successfully, characters are classified according to the rules of the default ASCII 7-bit coded character set (see setlocale(3C)). Each of the classification functions is a predicate that returns non-zero for true, zero for false. is defined for valid character class names as defined in the current locale. charclass is a string identifying a generic character class for which codeset-specific type information is required. The following class names are defined in all locales: and User-defined class names may be specified if supported by the current locale as defined by (see setlocale(3C)). returns a value of type that can be used in a subsequent call to or if charclass is not valid in the current locale. The classification functions return non-zero under the following circumstances, and zero otherwise: wc has the property defined by prop. wc is a letter. wc is a blank character; that is a space or tab. wc is an uppercase letter. wc is a lowercase letter. wc is a decimal digit (in ASCII: characters [0-9]). wc is a hexadecimal digit (in ASCII: characters [0-9], [A-F] or [a-f]). wc is an alphanumeric (letters or digits). wc is a character that creates "white space" in displayed text (in ASCII: space, tab, carriage return, new-line, vertical tab, and form-feed). wc is a punctuation character (in ASCII: any printing character except the space character(040), digits, letters). wc is a printing character. wc is a visible character (in ASCII: printing characters, excluding the space character(040)). wc is a control character (in ASCII: character codes less than 040 and the delete character(0177)). If the argument to any of these functions is outside the domain of the function, the result is 0 (false). Definitions for these functions and the types and are provided in the header. EXTERNAL INFLUENCES
Locale The category determines the classification of character type. International Code Set Support Single-byte and multibyte character code sets are supported. AUTHOR
was developed by IBM, OSF, and HP. SEE ALSO
ctype(3C), multibyte(3C), setlocale(3C), ascii(5), thread_safety(5). STANDARDS CONFORMANCE
wctype(3C)
All times are GMT -4. The time now is 04:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy