How to filter a whole line using a word?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to filter a whole line using a word?
# 1  
Old 10-27-2010
How to filter a whole line using a word?

Hello Team,

I have a script in which more than 500 trigger statemetns are written.

i need to filter all lines from that script file which containts "CREATE TRIGGER" word in each line

is it possible using linux commands??

example:

CREATE TRIGGER S1.T1
...............
..............
.......
END

CREATE TRIGGER s2.t2
............
........
.......
...
END
..
..
..
..


out put should

CREATE TRIGGER s1.t1
CREATE TRIGGER s2.t2
.....
...
kanakaraju
# 2  
Old 10-27-2010
Have a look at:
Code:
man grep

# 3  
Old 10-27-2010
Thanks for the reply.

i am trying this

grep -i create trigger trig1.sql | awk '{print "DROP TRIGGER\t" $4}'

after $4 i need a semi colon like

DROP TRIGGER X.Y ;

how to add semi colon here??

grep -i create trigger trig1.sql | awk '{print "DROP TRIGGER\t" $4 ";"}'

This is not working for me can any body suggest??
kanakaraju
# 4  
Old 10-27-2010
Try this, Its $3 not $4
Code:
grep -i create trigger trig1.sql | awk '{print "DROP TRIGGER\t" $3 ";"}'

# 5  
Old 10-27-2010
Use " ;" instead of ";" to get a space after the value.
# 6  
Old 10-27-2010
when i use this
grep -i create trigger trig1.sql | awk '{print "DROP TRIGGER\t" $4 ";"}'

its giving out put as

;ROP TRIGGER X.Y

how come??

even i tried this
grep -i create trigger trig1.sql | awk '{print "DROP TRIGGER\t" $4 " ;"}'

another kind of out put
;OP TRIGGER x.y

kanakaraju
# 7  
Old 10-27-2010
Post your input file trig1.sql
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter line in a script

Hi Team, I am trying hard to find a way I can filter a line as below: If I have a line as /abc /def 123:/ghi /jkl 456:/mno /pqrs 7890:/tuvw /xyz I am expecting my output to be as below: /abc /def /jkl /pqrs /xyz basically I want to ignore anything preceding or succeeding colon... (2 Replies)
Discussion started by: SiddhVi
2 Replies

2. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

3. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

4. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

5. UNIX for Dummies Questions & Answers

regular expression for replacing the fist word with a last word in line

I have a File with the below contents File1 I have no prior experience in unix. I have just started to work in unix. My experience in unix is 0. My Total It exp is 3 yrs. I need to replace the first word in each line with the last word for example unix have no prior experience in... (2 Replies)
Discussion started by: kri_swami
2 Replies

6. Shell Programming and Scripting

Adding a word in front of a word of each line.

Adding a word in front of a word of each line.In that line only one word will be there. pl help:( (4 Replies)
Discussion started by: Ramesh Vellanki
4 Replies

7. UNIX for Advanced & Expert Users

How to filter the words, if that word contains the expected letter

Hi, I am trying to filter the words from a file which contain 'abc'. But I am unable to. Could any one help me. For eg: The file contents are 123ab 12hnj1 123abc456 123cgbcahjkf23 23134abchfhj43 gc32abc abc1 2abc3 sd uiguif fhwe 21242 uh123 jkcas124d123 u3hdbh23u ffsd8 Output... (3 Replies)
Discussion started by: venu_eie
3 Replies

8. Shell Programming and Scripting

Read line by line not word by word

i have this line my,name,is,john stored in a file d.sh and i wish to print the line as string..but im getting word by word...have tried this......... for in $(cat $d.sh); do echo $i done but this is giving me my name is john (6 Replies)
Discussion started by: vadharah
6 Replies

9. UNIX for Dummies Questions & Answers

how to move word by word on command line

Hey All, On commad promt of a shell.. How can we move our cursor word by word. Like Ctrl+A takes to the starting of the command... Any shortcut like that..? Thanks pbsrinivas (1 Reply)
Discussion started by: pbsrinivas
1 Replies

10. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies
Login or Register to Ask a Question