GREP:Output all lines containing word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GREP:Output all lines containing word
# 1  
Old 04-06-2006
Question GREP:Output all lines containing word

Output all lines in the file temp that contain the word dog
using GREP only and in one line!!!

I tried grep '[[:space:]]dog[[:space:]]' temp

but it doesnt catch word dog when is at beginning or end, like:

Our dog is nice /this OK
Nice dog /this NOT
dog good /this NOT


Thank you!!!
# 2  
Old 04-06-2006
Try...
Code:
egrep '(^|[[:space:]])dog($|[[:space:]])' temp

# 3  
Old 04-06-2006
I would do:

grep ".*dog.*" temp
# 4  
Old 04-06-2006
Oops, my way would make the following acceptable:

"a furious bulldog"

so Ygor's got it.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to output non-number lines with grep?

I want to check my data quality. I want to output the lines with non-number. I used the grep command: grep '' myfile.csv Since my file is csv file, I don't want to output the lines with comma. And I also don't want to output "." or space. But I still get the lines like the following:... (8 Replies)
Discussion started by: twotwo
8 Replies

2. Shell Programming and Scripting

How to print few lines before and after matching word is found suing grep?

Hi, here are few lines present in the logs. I want to grep on Error and print few lines before and after Error word is found line1 Line2 Line3 Error Line4 Line5 Line6 Line7 I want the output to be Line2 Line3 Error Line5 (1 Reply)
Discussion started by: arghadeep adity
1 Replies

3. Shell Programming and Scripting

Grep word after last occurance of string and display next few lines

Hi, I wanted to grep string "ERROR" and "WORNING" after last occurrence of String "Starting" only and wanted to display two lines after searched ERROR and WORNING string and one line before. I have following cronjob log file "errorlog" file and I have written the code for same in Unix as below... (17 Replies)
Discussion started by: nes
17 Replies

4. Shell Programming and Scripting

awk - grep particular word from output

Hi Experts, - Getting error while using it through a variable to get the PID, PID=42 # UNIX95=1 ps -e -o pcpu,pid,ppid,stime,etime,args | awk '{if ($2~"^42$") print $0}' 0.00 42 0 Feb 10 600-17:21:29 nfs_async_io - But when using with a variable it is not working . #... (6 Replies)
Discussion started by: rveri
6 Replies

5. Shell Programming and Scripting

grep the output between specific lines

Symmetrix ID : 00000001234 Host Name : myown Identifiers Found : 5000000000000000 5000000000000001 Device Cap(MB) Attr Dir:P ------ ------- ---- ---- 1234 25886 (M) 8D:1, 9D:1 0123 25886 (M) 8D:1, 9D:1 1345 25886 (M) ... (5 Replies)
Discussion started by: maddy.san
5 Replies

6. UNIX for Dummies Questions & Answers

How to grep a word and the two lines before?

Hi I have this txt file getting from a lpstat command. XA40 XA40 0 Unknown 0 0 1 1 1 0 Unknown LPD 0 0 1 1 2 0 Unknown specified 0 0 1 1 3 XA99 @spip READY : (FATAL ERROR) 0781-233 Unknown host spiprs01.mon.local. XA01 @xs00 READY XA01 XA01 0 Unknown 0 0 1 1 1 0 Unknown LPD 0 0 1 1... (5 Replies)
Discussion started by: npatao71
5 Replies

7. Shell Programming and Scripting

How to filter only the last 'n' lines of a grep output?

I am running a grep query for searching a pattern, and the output is quite huge. I want only the last 200 lines to be displayed, and I am not sure if tail will do the trick (can tail read from std in/out instead of files?). Please help me out. (1 Reply)
Discussion started by: shell_newbie
1 Replies

8. Shell Programming and Scripting

Grep multiple line pattern and output the lines

Hi I have the following Input -- -- TABLE: BUSINESS_UNIT -- ALTER TABLE RATINGS.BUSINESS_UNIT ADD CONSTRAINT FK1_BUSINESS_UNIT FOREIGN KEY (PEOPLESOFT_CHART_FIELD_VALUE_ID) REFERENCES RATINGS.PEOPLESOFT_CHART_FIELD_VALUE(PEOPLESOFT_CHART_FIELD_VALUE_ID) ; ALTER TABLE... (1 Reply)
Discussion started by: pukars4u
1 Replies

9. Shell Programming and Scripting

grep lines containing a word only twice.

Hi, I have a query on using grep options. I tried with several options but unable to do it. lanite:52> cat note 123 456 ab 123 ab cv 234 4566 67 ab gh tij ab 12 34 ab ab cv dfgv ab cv ab kjhk ab ghj sdf dfg ab jljklj ab Now, I need to use grep to find the line which contains the... (6 Replies)
Discussion started by: dilipr25
6 Replies
Login or Register to Ask a Question