The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need Regular expression svenkatareddy Shell Programming and Scripting 4 08-17-2009 12:08 PM
regular expression [^ ] iengca Shell Programming and Scripting 9 06-18-2008 09:45 AM
Regular expression Help Harikrishna Shell Programming and Scripting 3 06-11-2008 08:20 AM
regarding lex regular expression axes High Level Programming 1 03-12-2007 03:00 AM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 10:59 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-13-2009
wakatana wakatana is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 36
regular expression foreign language

Hello all,
I read somewher that regular expressions work with ASCII table so when i type
Code:
grep "[a-z][a-z]*" file_name
it uses values from ACII dec97(a) to dec122(z), right ?
But if I have file containing diacritics, lets say (ordinary Slovak language characters):
Code:
marek@cepi:~$ cat diakritika 
áôúéťľúľščťžýáíéôäúú
ÁôúÉŤĽÚĽŠČŤŽÝÁÍÉôäÚÚ

marek@cepi:~$ grep -o "[a-z][a-z]*" diakritika 
áôúéťľúľščť
ýáíéôäúú
ôú
ôä
Why this regexp know diacritics? And why know only lower case and not "ž" ??? This is strange for me. Friend told me it could be something with $LANG. So my $LANG is:
Code:
marek@cepi:~$ echo $LANG
en_US.UTF-8
Also I would ask if I want uppercase file with diacritic i type:
Code:
marek@cepi:~$ cat diakritika | tr "[:lower:]" "[:upper:]"
áôúéťľúľščťžýáíéôäúú
ÁôúÉŤĽÚĽŠČŤŽÝÁÍÉôäÚÚ
why it not change lower to upper ?
Thanks a lot for reply
PS: I hope that characters display properly
  #2 (permalink)  
Old 10-17-2009
wakatana wakatana is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 36
maybe i know why is "ž" different it is "behind" z so regex [a-z] did not match the "ž" but still many thinngs are unclear
  #3 (permalink)  
Old 10-17-2009
Scrutinizer Scrutinizer is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 637
Quote:
Originally Posted by wakatana View Post
why know only lower case
If you want uppercase as well you have to specify
Code:
grep "[a-zA-Z][a-zA-Z]*" file_name

Last edited by Scrutinizer; 10-17-2009 at 10:09 AM..
  #4 (permalink)  
Old 10-17-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,920
What you are discusiing is called a collating sequence. Do a web search for "POSIX collating sequence" for further information.

To be language-neutral, your example would be written as
Code:
grep "[[:alpha:]][[:alpha:]]*"  filename
or if you only want lowercase characters
Code:
grep "[[:lower:]][[:lower:]]*"  filename
  #5 (permalink)  
Old 10-17-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by wakatana View Post
Hello all,
I read somewher that regular expressions work with ASCII table so when i type
Code:
grep "[a-z][a-z]*" file_name
it uses values from ACII dec97(a) to dec122(z), right ?
But if I have file containing diacritics, lets say (ordinary Slovak language characters):
Code:
marek@cepi:~$ cat diakritika 
áôúéťľúľščťžýáíéôäúú
ÁôúÉŤĽÚĽŠČŤŽÝÁÍÉôäÚÚ

marek@cepi:~$ grep -o "[a-z][a-z]*" diakritika 
áôúéťľúľščť
ýáíéôäúú
ôú
ôä
Why this regexp know diacritics? And why know only lower case and not "ž" ??? This is strange for me. Friend told me it could be something with $LANG.

ž comes after z, so it is not in the range you gave.
Quote:
So my $LANG is:
Code:
marek@cepi:~$ echo $LANG
en_US.UTF-8
Also I would ask if I want uppercase file with diacritic i type:
Code:
marek@cepi:~$ cat diakritika | tr "[:lower:]" "[:upper:]"
áôúéťľúľščťžýáíéôäúú
ÁôúÉŤĽÚĽŠČŤŽÝÁÍÉôäÚÚ
why it not change lower to upper ?

Probably because those characters are not part of the en_US.UTF-8 definition of [:lower:] and [:upper:].
  #6 (permalink)  
Old 10-18-2009
wakatana wakatana is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 36
Thank you for reply. Is there an option how to convert lowercase diacritics to uppercase ?
  #7 (permalink)  
Old 10-18-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

Use a locale in which they are defined. (I guess; I haven't tried it.)
Reply

Bookmarks

Tags
encoding, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0