grep and alphanumerics


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep and alphanumerics
# 1  
Old 10-26-2012
grep and alphanumerics

Hi Experts,

I'm facing an issue with grep or may be Im missing something. Following are the details

Code:
Input file

[root@#### ~]# more regexp
asdh1987

dog897you
981towm

1234oqn
4yuop8pou
sam99917c00l
Akoold0g8
data
sample data

Im trying to grep out only the alphanumeric entries and following is the output
Code:
[root@#### ~]# grep -Ei '[:alnum:]' regexp
asdh1987
dog897you
981towm
1234oqn
4yuop8pou
sam99917c00l
Akoold0g8
data
sample data

However when i do the same thing using the following command it works

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

Am i missing something, please advise
# 2  
Old 10-26-2012
The RE you used ([:alnum:]) matched lines that contained an 'a', 'l', 'n', 'u', 'm', or ':'. To specify an RE with a bracket expression matching any character in the alnum character class, you need to use [[:alnum:]].
# 3  
Old 10-26-2012
Not working

I have used the following command

Code:
[root@nagois ~]# grep '[[:alnum:]]' regexp
asdh1987
dog897you
981towm
1234oqn
4yuop8pou
sam99917c00l
Akoold0g8
data
sample data

It is dumping all the entries excluding blank lines but not alpha numeric entries
# 4  
Old 10-26-2012
Alphanumeric means lowercase, uppercase or numeric...
# 5  
Old 10-26-2012
Very true

however the grep is pulling up

Code:
data
sample data

which are only lower case
# 6  
Old 10-26-2012
The bracket expression [[:alnum:]] will match one of the characters A-Z,a-z,0-9; that's a single-character pattern. If your line has at least one of these characters, the pattern will match.
# 7  
Old 10-26-2012
Code:
[:alnum:]  - Any digit or Alphanumeric
[:alpha:]  - Any Alphanumeric

May be this could be the reason. Try using [:alpha:]

Elixir has good point here.Smilie

Please check http://ss64.com/osx/grep_pattern.html
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