Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed: removing alphanumeric words from a file

I have file with a lot of text, what I want to do is to remove all alphanumeric words.

Example of words to be removed:

gr8  
2006  
sdlfj435ljsa  
232asa  
asld213  
ladj2343asda
asd!32  

what is the best way I can do this?

like image 917
daydreamer Avatar asked Dec 13 '10 20:12

daydreamer


1 Answers

If you want to remove all words that consist of letters and digits, leaving only words that consist of all digits or all letters:

sed 's/\([[:alpha:]]\+[[:digit:]]\+[[:alnum:]]*\|[[:digit:]]\+[[:alpha:]]\+[[:alnum:]]*\) \?//g' inputfile

Example:

$ echo 'abc def ghi 111 222 ab3 a34 43a a34a 4ab3' | sed 's/\<\([[:alpha:]]\+[[:digit:]]\+[[:alnum:]]*\|[[:digit:]]\+[[:alpha:]]\+[[:alnum:]]*\) \?//g'
abc def ghi 111 222
like image 114
Dennis Williamson Avatar answered Nov 15 '22 10:11

Dennis Williamson