How to specify 'not case sensitive' in regex (nawk, sed, patern expencions)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to specify 'not case sensitive' in regex (nawk, sed, patern expencions)?
# 1  
Old 08-15-2008
How to specify 'not case sensitive' in regex (nawk, sed, patern expencions)?

Is it possible to make the search in regular exprecion or in matching parts of sed, nawk and others to IGNORE the case of the search string?

I mean, like if used 'grep' with -i option:
> grep -i "abc" file

I would like to be able to do the same, say, by nawk:
> nawk '/abc/ {print $0}' file
or sed:
> sed -n '/abc/ p' file
or for expancion:
> echo ${var/abc/ found }
- but all that is the case sensitive!

Is there a way to make all those searches not case sensitive, exept having every letter in the way, like [Aa] ?

Appreciate your help!

Last edited by alex_5161; 08-15-2008 at 08:16 PM..
# 2  
Old 08-15-2008
Code:
 
/regex/i

Ed: Now that I've said that, I'm not so sure it would actually work for the apps you mention.

Last edited by Vi-Curious; 08-15-2008 at 09:40 PM.. Reason: Add a comment
# 3  
Old 08-15-2008
gsed (GNU sed) V3.02 has the I flag.
gawk had the IGNORECASE option.
# 4  
Old 08-15-2008
In sed (regular, standard sed, not some obscure derivate) it is a little cumbersome, but can be done:

Code:
sed -n '/[Rr][Ee][Gg][Ee][Xx]/p'

Alternatively, thefollowing could also work: copy every line to the holdspace, use the "y"-subcommand to translate the phrase in qestion to all upper or lower case and then search for that. If it is found, replace the pattern space with the hold spaces content (which is the unchanged line) and print it:

Code:
sed -n 'h
        y/REGX/regx/
        /regex/ {
             x
             p
        }'

I hope this helps.

bakunin
# 5  
Old 08-15-2008
In nawk you can use the tolower function to do regex matching (I just saw this in another thread a minute ago):


Equivalent to grep -i abc (I hope):

nawk '
tolower($0) ~ /abc/ {print }
'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help me in using case sensitive command

Hello All, Please help me with this I need to create a cronjob that should delete all files which are older than 30days with '*.txt' and should not delete files with '*TEST*.txt' either file name TEST is upper or test lower case sensitive here's the script /DIR -type f -name '*.txt'... (7 Replies)
Discussion started by: krish_007
7 Replies

2. Shell Programming and Scripting

Repeated lines-case sensitive

Hi, users file contains below names i have a requirement to keep only one case sensitive user. For e.g if user name is "aaa" then only aaa should be there in the file and other matching users(AAA,aaA) should be deleted. Tried multiple options but no luck can you please help. aaa abc AAA... (2 Replies)
Discussion started by: Satyak
2 Replies

3. Shell Programming and Scripting

Case sensitive in If loop .

Hi All, select app from the menu: ABC DEF GHI JKL ALL # ALL will select all the apps in the menu echo "Enter your option" read option; if then <execute the below command> elif # option is the 1 selection from menu...not ALL <execute the below command> else (14 Replies)
Discussion started by: Devaraj A
14 Replies

4. Shell Programming and Scripting

Awk-sed : Question getting case sensitive filed.

Experts, Good day!, I have following data, I want to filter 3rd Field, if it is in UPPERCASE, aa aa1 HOST1 aa bb1 host2 aa cc1 SERV1 aa dd1 SERV2 ab aa1 host3 The output should be: aa aa1 HOST1 aa cc1 SERV1 aa dd1 SERV2 (2 Replies)
Discussion started by: rveri
2 Replies

5. UNIX for Dummies Questions & Answers

How to take parameters as non case sensitive

Is there a way for me to take a parameter then store it in a variable and use its value as non case sensitive? Ex. Lets say i have a parameter which contains "Hey". Then im gonna store it to GR using GR=$1. CL=/install/$GR.g How can i make GR non case sensitive so that the... (1 Reply)
Discussion started by: khestoi
1 Replies

6. Solaris

Tcp_conn_req_max_q (CASE-sensitive?)

I was instructed by my superior to change kernel parameter, adding up this parameter to /etc/system. Server is Solaris 10 on SPARC. Tcp_conn_req_max_q 1024In my Google search, all I know that the sentence is in small case (tcp_conn_req_max_q) but as you can see above, instruction given... (4 Replies)
Discussion started by: Olli.Lang
4 Replies

7. Shell Programming and Scripting

Ignore case sensitive in Case Switch

In a Case switch, how to ignore case sensitive in the test: e.g. case "$field" in "TEST) action1;; *) action2;; esac How to go in action1 in case of $field = TEST , or Test , or test or .... without enumerating all possibilities... Thanks,... (1 Reply)
Discussion started by: annelisa
1 Replies

8. UNIX for Dummies Questions & Answers

how to disable case sensitive on RHEL ?

Hi all, Im newbie, can i disable case sensitive on RHEL environment, and how? Thank you. (2 Replies)
Discussion started by: blesets
2 Replies

9. UNIX for Dummies Questions & Answers

Is Hostname Case sensitive ?????

Hello users, I have a question ? I was just wondering whether the hostname on unix systems are case sensitive. For example in the system which I work. ping TestHost and ping testhost gives me the same output i.e I get the reply from the remote host Is this applicable for all... (3 Replies)
Discussion started by: ajphaj
3 Replies

10. UNIX for Dummies Questions & Answers

Unix user ID's case-sensitive?

It has been quite a while since I used UNIX. I am developing a security system and I was wondering if UNIX and/or LINUX user ID's are case-sensitive. i.e. can user 'daveb' and 'Daveb' exist on the same system with completely different authorizations/priorities, etc.? (3 Replies)
Discussion started by: dmilleville
3 Replies
Login or Register to Ask a Question