Making case insensitive in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making case insensitive in awk
# 22  
Old 01-06-2012
Quote:
Originally Posted by vivek d r
the bug is still persisting...
Code:
 firstword="CREATE VIEW View11"
[root@dunkin-ds-dev-103 vivek]# awk "/$firstword/,/;$/ {print}" tble2 | awk '!x[$1]++' > procextract2.sql
[root@dunkin-ds-dev-103 vivek]# cat procextract2.sql
        CREATE VIEW View11
        AS
           SELECT User.id AS userId,
                  User.userCDIId AS userCDIId,
                          Button.id AS buttonId,
                  includeInCallHistory,
                  data AS pOCData,
                  Button.pointOfContactId AS pointOfContactId
            FROM User, UserCDI, Button, PointOfContact
            WHERE User.userCDIId = UserCDI.id
                  AND Button.parentUserCDIId = UserCDI.id
[root@dunkin-ds-dev-103 vivek]#

is it because i used variable $firstword...?
--------------------------------------------------------
i found out.. its because of this | awk '!x[$1]++'
when i executed the command excluding this, i was getting proper output... but that is required in case there are more than one view of same name..
Use single quoting for awk statement ...
# 23  
Old 01-06-2012
i fixed that i need help in the previous post about making case insensitive code to display create table structures....
# 24  
Old 01-06-2012
In awk you can use conditions like :

Code:
(tolower($0)~/delimiter/)

or

Code:
(toupper($0)~/DELIMITER/)

# 25  
Old 01-06-2012
Quote:
Originally Posted by vivek d r
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]#

i need help in the above scenario
# 26  
Old 01-06-2012
Cascading new requirement over the posts turn the thread into tedious to follow.

Since Ahmed provided you a working solution for your initial question, i think you should start a new thread with a full description of your new problem , a representative sample of your input file as well as the output you expect.
# 27  
Old 01-06-2012
okay will do that.... i thought of opening a new thread for this but then comebody will post that its duplicate or its similiar to my previous threads.. so posted in my old thread.... will open a new thread now...
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