Making case insensitive in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making case insensitive in awk
# 8  
Old 12-27-2011
Try escaping the pipe...
Code:
sed -n "/$firstword(/,/[dD]elimiter\|DELIMITER/p" onlyproc1.sql | ...

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 9  
Old 12-28-2011
thanks a lot.. it worked :-)

---------- Post updated 28-12-11 at 12:31 PM ---------- Previous update was 27-12-11 at 04:05 PM ----------

One more hiccup again....
here is the content of a file..
Code:
cat views.sql
DROP VIEW IF EXISTS View11;
        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
                  AND Button.pointOfContactId = PointOfContact.id
                  AND buttonType = 'PointOfContact';
 
        DROP VIEW IF EXISTS View22;
        CREATE VIEW View22
        AS
           SELECT User.id AS userId,
                  User.userCDIId AS userCDIId,
                  data AS personalPOCData,
                  Button.personalPointOfContactId AS personalPointOfContactId
            FROM User, UserCDI, Button,PersonalPointOfContact
            WHERE User.userCDIId = UserCDI.id
                  AND Button.parentUserCDIId = UserCDI.id
                  AND Button.personalPointOfContactId = PersonalPointOfContact.id
                  AND buttonType = 'PersonalPointOfContact';

i am trying to extract one view at a moment starting from create view to ';' which marks its end...
i was using the below few commands
Code:
firstword="CREATE VIEW View11"
 
 sed -n "/$firstword\$/,/;/p" views.sql | awk '!x[$1]++' > procextract.sql 
#the above commands extracts that prticular view and paste to procextract.sql
 
echo "`sed "/$firstword\$/,/;/d" views.sql `" > views.sql 
#the above command deletes that particular view from the views.sql file

when i tried the command say first command which extracts a particular view its not exactly cutting it from "create view view_name" to ";" rather last one or two lines are missing..
here is the output..
Code:
cat procextract.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

here last two lines are missing that is
Code:
AND Button.pointOfContactId = PointOfContact.id
AND buttonType = 'PointOfContact';

are missing.. so how to rectify this bug....?

---------- Post updated at 01:44 PM ---------- Previous update was at 12:31 PM ----------

can anyone help me on this one...?

Last edited by vivek d r; 12-28-2011 at 03:12 AM..
# 10  
Old 12-28-2011
Code:
$ awk '/CREATE VIEW View11/,/;$/ {print}' views.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
          AND Button.pointOfContactId = PointOfContact.id
          AND buttonType = 'PointOfContact';

# 11  
Old 12-28-2011
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..
# 12  
Old 12-28-2011
with awk
Code:
$ awk 'BEGIN{ IGNORECASE=1 } /CREATE PROCEDURE/,/delimiter/' "$file1" > onlyproc1.sql


Last edited by Franklin52; 01-06-2012 at 05:49 AM.. Reason: Please use code tags for code and data samples, thank you
# 13  
Old 12-28-2011
Why are you using ... | awk '!x[$1]++' ? Try without that, it is working... I understand awk is for uniquel ines, but thats not required here.

--ahamed

---------- Post updated at 01:37 AM ---------- Previous update was at 01:35 AM ----------

Ok, just read your post that you found out the issue. For eliminating duplicate ones, you will need to put in some login.

--ahamed
# 14  
Old 12-28-2011
i removed that awk '!x[$1]++' from the code and its working fine but what if there are two views of the same name..? two views will be present in the extracted file (if that scenario comes)...

---------- Post updated at 04:37 PM ---------- Previous update was at 03:39 PM ----------

is there any way i could copy only one of the duplicates into a file rather than 2?
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