grep and alphanumerics


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep and alphanumerics
# 8  
Old 10-27-2012
tried [:alpha:]

Code:
[root@#### ~]# grep "[:alpha:]" regexp
asdh1987
4yuop8pou
sam99917c00l
Akoold0g8
data
sample data
NetWorkManager781C00l

It is missing out

Code:
981towm
1234oqn

Which also happen to be Alpha numeric. Any ideas.

Thanks
Syed

---------- Post updated at 11:50 AM ---------- Previous update was at 11:17 AM ----------

Code:
[root@#### ~]# grep -Ei "[a-z][0-9]|[0-9][a-z]" regexp
asdh1987
dog897you
981towm
1234oqn
4yuop8pou
sam99917c00l
Akoold0g8
NetWorkManager781C00l

and for some reason [:alpha:] and [:alnum:] are not yeilding the desired result.

Note: I have not used [:alpha:] and [:alnum:] in the past.
# 9  
Old 10-27-2012
Hi there,
please make it a point to read all the replies to the thread carefully before asking further questions. Your question has already been answered by Don Cragun in post #2 of this thread.
# 10  
Old 10-28-2012
elixir_sinari

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.
# 11  
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question