making sed command case insensitive


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting making sed command case insensitive
# 1  
Old 01-09-2012
making sed command case insensitive

i have something like this in a file

Code:
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;
.
.
.
 
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;
.
.
blah blha etc etc
.
.

i am performing the below operations

Code:
firstword="CREATE TABLE  ReplicatorInfo  ("
endpoint="engine=Innodb"
echo "`sed -n "/$firstword/,/$endpoint/ w tablextract.sql" < onlytables.sql`"

what the sed statement does is, extracts the table "ReplicatorInfo" and pastes it into tablextract.sql.... but its not functioning properly because the end point is lowercase but in fact the endpoint should be in upper case since it is same way in main file... so can anyone please help me to modify same sed command so that endpoint is considered as case insensitive.. :-/
# 2  
Old 01-09-2012
Can't you give as endpoint="ENGINE=INNODB" as in the file
# 3  
Old 01-09-2012
no the variable endpoint is fixed... what if i want to extract "NextID". it will not extract it since endpoint willl have upper case. so i want to make only the endpoint as case insensitive in sed command
# 4  
Old 01-09-2012
Ok.But i dont understand completely, however in general there are couple of ways

1. If your sed supports case insensitive operator I then it would be simple to solve sed '/ReplicatorInfo/,/engine=Innodb/I!d'

2. Change the variable assignment as endpoint="[Ee][Nn][Gg][Ii][Nn][Ee].. etc and try.

3. Convert all the characters either to upper or lower case in pattern space and print the required, but this would require to change the variable assignment firstword and endpoint
Code:
firstword='REPLICATORINFO'
endpoint='ENGINE=INNODB'
sed -n "h;y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/;/$firstword/,/$endpoint/{x;P}" inputfile

4. Perl solution which has case insensitive operator i

Last edited by michaelrozar17; 01-09-2012 at 05:06 AM..
This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 01-09-2012
Code:
$ firstword="CREATE TABLE  ReplicatorInfo  ("
$ endpoint="engine=Innodb"
$ sed -n "/$firstword/,/$endpoint/Ip" input
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;


------------------------------------------------------
Late post. Already replied by michaelrozar17.

Last edited by balajesuri; 01-09-2012 at 04:28 AM.. Reason: Late post
This User Gave Thanks to balajesuri For This Post:
# 6  
Old 01-09-2012
thanks balajesuri and michaelrozar17... the code worked.. i was trying with small case 'i' but it was not working... upper case 'I' did the job.. thanks a lot :-)
# 7  
Old 01-09-2012
FYI, a small 'i' refers to insert, just as in vi.
For e.g.: sed '1i First line of file' inputfile would insert the text as first line of file and print the contents on STDOUT.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

Command for a case insensitive search

Hi All, What is the command to search a file for a case-insensitive match 1.grep -nc text filename 2.grep -i text filename 3.grep -i filename text 4.grep -nc filename text 5.grep -c text filename Thanks for your help (1 Reply)
Discussion started by: bobby1015
1 Replies

3. 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

4. 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

5. Shell Programming and Scripting

Making case insensitive in awk

here is a statement awk '/CREATE PROCEDURE/,/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... (26 Replies)
Discussion started by: vivek d r
26 Replies

6. 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

7. UNIX for Dummies Questions & Answers

Using sed for case insensitive search

Hi, I have a file named "test_file" that has the below content. It has words in upper/lower cases PRODOPS prodOPS ProdOps PRODops escalate Shell My requirement is to replace all the "prodops" (what ever case it may be) with "productionoperations". I tried using the "i" option with... (7 Replies)
Discussion started by: sbhuvana20
7 Replies

8. UNIX for Dummies Questions & Answers

more command case insensitive search ?

Hello, How do I set case insensitive search mode while the file is open with more command ? (I know -i option which could be used before opening) thanks Vilius (2 Replies)
Discussion started by: vilius
2 Replies

9. Shell Programming and Scripting

How to make sed case insensitive

I need to remove a pattern say, ABCD whether it is in uppercase or lowercase from a string. How to do it using SED? for example ABCDEF should output to EF abcdEF should also output to EF (2 Replies)
Discussion started by: vickylife
2 Replies

10. Shell Programming and Scripting

case insensitive

hi everyone, I need to do the following thing in a case insesitive mode sed 's/work/job/g' filename since work could appear in different form as Work WORK WorK wORK,.... I was wondering if i could do a case insensitive search of a word. thanks in advance, :) (4 Replies)
Discussion started by: ROOZ
4 Replies
Login or Register to Ask a Question