Making case insensitive in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making case insensitive in awk
# 1  
Old 12-27-2011
Making case insensitive in awk

here is a statement
Code:
awk '/CREATE PROCEDURE/,/[dD]elimiter/' "$file1" > onlyproc1.sql

which mean cut from create procedure to Delimiter or delimiter and paste it in onlyproc1.sql... my query is how to make this case insensitive.. that is i want the above code to work whther it is Delimiter or delimiter or DEMILITER..

do i have to use something like this or is there any shortway to make it case insensitive...?
Code:
awk '/CREATE PROCEDURE/,/[dD][eE][lL][iI][mM][iI][tT][eE][rR]/' "$file1" > onlyproc1.sql

# 2  
Old 12-27-2011
Not sure if mine is shorter

Code:
awk '/CREATE PROCEDURE/,/delimiter|DELIMITER/' "$file1" > onlyproc1.sql

One more thing, yours has an advantage of picking data even if it in this format "DeLiMiTeR" i.e. a mixed case!
Mine will look only for "delimiter" or "DELIMITER"

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 12-27-2011
thanks but would it work for Delimiter... that is first letter capital...
so if i do it this way

Code:
awk '/CREATE PROCEDURE/,/delimiter|DELIMITER|Delimiter/' "$file1" > onlyproc1.sql

it should work right?
# 4  
Old 12-27-2011
Yes, that should also work.

If you think only the fist letter is going to be an issue, you can do this... /[Dd]elimiter/

If you are uncertain which is gonna be what, I think your solution holds good!

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 5  
Old 12-27-2011
thanks i tried
Code:
awk '/CREATE PROCEDURE/,/delimiter|DELIMITER|Delimiter/' "$file1" > onlyproc1.sql

it worked fine :-)..
# 6  
Old 12-27-2011
Code:
awk '/CREATE PROCEDURE/,/[Dd]elimiter|DELIMITER/' "$file1" > onlyproc1.sql

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 7  
Old 12-27-2011
oh this one is better.. thanks :-)

---------- Post updated at 02:56 PM ---------- Previous update was at 02:51 PM ----------

Code:
sed -n "/$firstword(/,/[dD]elimiter|DELIMITER/p" onlyproc1.sql | awk '!x[$1]++' > procextract1.sql

is there something wrong in above...? cause earlier i used to do
Code:
sed -n "/$firstword(/,/[dD]elimiter/p" onlyproc1.sql | awk '!x[$1]++' > procextract1.sql

it was working fine but when i added '|' to it which i thought would be similiar syntax to awk, the above statement is not functioning properly Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using awk to search case insensitive

Hello , Using the below scrip to search a string in a file , by case-insensitively Please assist on using the toupper() as getting error !. #!/usr/bin/ksh set -x curr_dir=`pwd` file_ctr=0 printf "\n Reviewing the output file from the directory: %s \n\n" $curr_dir ls -latr ... (4 Replies)
Discussion started by: Siva SQL
4 Replies

2. UNIX for Beginners Questions & Answers

Making SED case insensitive

Dears, In the below string, please let me know how to make the sed search case-incensitive. I have more such lines in my script instead of let me know any other easier option. sed -n '/dn: MSISDN=/,/^\s*$/p' full.ldif > temp ; sed -n... (4 Replies)
Discussion started by: Kamesh G
4 Replies

3. Shell Programming and Scripting

Output piped to case insensitive awk

I have an encrypted password file, and I've created a simple script to search the password file for a particular record. There are multiple lines per record, so I'm using a record delimiter. #!/bin/bash PATTERN=$1 openssl des3 -d -salt -in ~/docs/pass.des3 | awk '{ FS="\n" ; RS="*" }... (2 Replies)
Discussion started by: 0rac1e
2 Replies

4. Shell Programming and Scripting

Use case insensitive variable in ksh shell scripting using sed or awk

I am using a variable called $variable in a pattern search to print from a starting variable to a constant value. the variable search should be case in sensitive. i tired using Ip at the end in the below command. but in ksh it is not working. sed -n "/$variable/,/constant/p" file i also... (11 Replies)
Discussion started by: johnjs
11 Replies

5. Shell Programming and Scripting

making sed command case insensitive

i have something like this in a file cat onlytables.sql create table NextID ( id int auto_increment, zoneID int, entityName varchar(64), nextID int, lastModified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary... (6 Replies)
Discussion started by: vivek d r
6 Replies

6. Shell Programming and Scripting

Making case insensitive perl statement

cat > tble blah blah blah sdfsdf dsdf sdf .d.f ..df .. sdf.. create table NextID ( id int auto_increment, zoneID int, entityName varchar(64), nextID int, lastModified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary... (6 Replies)
Discussion started by: vivek d r
6 Replies

7. Shell Programming and Scripting

Making expr match case insensitive...

here is the condition i am using ] how to make this case insesntive... that is it should work with smaller case of "index" too... (11 Replies)
Discussion started by: vivek d r
11 Replies

8. Shell Programming and Scripting

case-insensitive search with AWK

Hi All, How we can perform case-insensitive search with AWK.:rolleyes: regards, Sam (11 Replies)
Discussion started by: sam25
11 Replies

9. Shell Programming and Scripting

awk case-insensitive

can I tell awk to be case insensitive for one operation without setting the ignorecase value ? thanks, Steffen (7 Replies)
Discussion started by: forever_49ers
7 Replies

10. Shell Programming and Scripting

Case-insensitive serach with awk

Is there any way to do case insensitive search with awk for the below statement: month1=`awk '/month/' ${trgfile} | cut -d"=" -f2` the "month" could come as Month, mOnth,MONTH etc. in a file. Now I am looking for "month".... Thanks, AC (4 Replies)
Discussion started by: acheepi
4 Replies
Login or Register to Ask a Question