Making case insensitive in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making case insensitive in awk
# 15  
Old 12-28-2011
Try this...
Code:
awk '{if($3~v){a=1}}a;/;/{exit}' v=View11  infile

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 16  
Old 12-28-2011
thanks a lot.. the above code worked.. :-) :-)

---------- Post updated at 06:18 PM ---------- Previous update was at 06:00 PM ----------

hey i got a bug for the above code.. here is the output..
Code:
 name="\`mfuBucketUpdate\`"
[root@dunkin-ds-dev-103 vivek]# echo "`awk '{if($3~v){a=1}}a;/;/{exit}' v="$name" procextract2.sql`" > procextract2.sql
[root@dunkin-ds-dev-103 vivek]# vi procextract2.sql
[root@dunkin-ds-dev-103 vivek]# cat procextract2.sql
CREATE PROCEDURE `mfuBucketUpdate`(IN chId int, OUT mfId int, OUT uId int)
   BEGIN
      DECLARE vcount    int DEFAULT 0;
[root@dunkin-ds-dev-103 vivek]#

the initial contents of procextract2.sql is
Code:
cat procextract2.sql
CREATE PROCEDURE `mfuBucketUpdate`(IN chId int, OUT mfId int, OUT uId int)
   BEGIN
      DECLARE vcount    int DEFAULT 0;
      DECLARE vId       int DEFAULT 1;
      DECLARE vpocId    int;
      DECLARE vppocId   int;
      DECLARE vuserId   int;
      SET vpocId =
             (SELECT pointOfContactId
                FROM CommunicationHistory CH
               WHERE CH.id = chId);
      SET vppocId =
             (SELECT personalPointOfCon
etc etc 
.
.
.

the procextract2.sql has only one procedure.... for this condition it worked when i tried with some other procedure but for this procedure its not working....
# 17  
Old 12-28-2011
It is very obvious that it will not work!
It is not a bug, we were dealing with views till now and suddenly you being in procedures and say it is not working?

--ahamed
# 18  
Old 12-28-2011
i was using the code for both procedures and views.... but the code should work for any names right either procedures or views
Code:
echo "`awk '{if($3~v){a=1}}a;/;/{exit}' v="$views" procextract2.sql`" > procextract2.sql

in the code /;/ mentioned specifies the end point right?

so
Code:
echo "`awk '{if($3~v){a=1}}a;/[dD]elimiter\|DELIMITER/{exit}' v="$views" procextract2.sql`" > procextract2.sql

is for procedures right.... but what is that ';' after 'a' is it the syntax or view specific?

Last edited by vivek d r; 12-28-2011 at 09:13 AM..
# 19  
Old 12-28-2011
";" after "a" is syntax

--ahamed
# 20  
Old 12-29-2011
Code:
cat tablextract2.sql
CREATE PROCEDURE after72DeleteTgr(id int)
BEGIN
END
$$
Delimiter ;
CREATE PROCEDURE after72DeleteTgr(id int)
BEGIN
END
$$
Delimiter ;
[root@dunkin-ds-dev-103 vivek]#
[root@dunkin-ds-dev-103 vivek]# proc_name1="after72DeleteTgr"
[root@dunkin-ds-dev-103 vivek]#
[root@dunkin-ds-dev-103 vivek]#  echo "`awk '{if($3~v){a=1}}a;/[dD]elimiter\|DELIMITER/{exit}' v="$proc_name1" tablextract2.sql`" > tablextract2.sql
[root@dunkin-ds-dev-103 vivek]# cat tablextract2.sql
CREATE PROCEDURE after72DeleteTgr(id int)
BEGIN
END
$$
Delimiter ;
CREATE PROCEDURE after72DeleteTgr(id int)
BEGIN
END
$$
Delimiter ;

is this because $3 will be looking for "after72DeleteTgr" and not after72DeleteTgr(...) as the startpoint....?

---------- Post updated at 02:17 PM ---------- Previous update was at 12:06 PM ----------

........
# 21  
Old 01-06-2012
i want the code to work for either "engine=innodb" or "ENGINE=INNODB" or any characters upper or lower that is caseInsensitively.. i thought the code which i had worked case insenstively but it dint.. can anyone please help me out, i want to modify the same code so that it acts case insenstively....

Code:
 cat > tble
create table NextID (
        id int auto_increment,
        zoneID int,
        entityName varchar(64),
        nextID int,
        lastModified TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        primary key(id)
) engine=Innodb;
CREATE TABLE  ReplicatorInfo  (
   id  INT(11) NOT NULL AUTO_INCREMENT,
   lastMessageReceivedTime   TIMESTAMP DEFAULT 0,
   lastModified  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY ( id )
)ENGINE=INNODB;
[root@dunkin-ds-dev-103 vivek]#  perl -e 'print reverse <>' "tble"|perl -lne '(/\s+engine=Innodb/i .. /create\s+table/i) && print;'|perl -e 'print reverse <>' > onlytables.sql
[root@vivek]#
[root@vivek]#
[root@vivek]# 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 key(id)
) engine=Innodb;
[root@vivek]#

---------- Post updated at 03:09 PM ---------- Previous update was at 02:32 PM ----------

Can anyone help me out please...!!!

Last edited by vivek d r; 01-06-2012 at 05:08 AM..
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