Find Exactly word in grep command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find Exactly word in grep command
# 1  
Old 08-23-2007
Error Find Exactly word in grep command

Hi all


How can i find Exactly line using grep.
my input file:
avg_configfile:
Recalculation Dates|4|
Recalculation|147|

I tryed like;
grep ^"Recalculation" avg_configfile

out put;
Recalculation Dates|4|
Recalculation|147|

But i want second line avg_configfile.i.e Recalculation|147| only.
please help me on this.
# 2  
Old 08-23-2007
If you want to match EXACTLY the second line do:

Code:
grep "^Recalculation\|147\|$" avg_configfile

# 3  
Old 08-23-2007
Rama,
if you want to find the exact word just put that word in the grep command.If the word is same it will give you multiple occurences.

eg.
if a string is like this

hi i am mosotronic.
mosotronic123 is a good boy.
mosotronic is studying unix.

some thing like that.

if you do a grep for robotroninc it will grep you all the 3 occuremces of the word.but if you want to find robotronic123 just give the exact word inside quotes it will do the things for you.

In youe question both the words are diff so just put the exact word as suggested by robotronic.
# 4  
Old 08-23-2007
Quote:
Originally Posted by robotronic
If you want to match EXACTLY the second line do:

Code:
grep "^Recalculation\|147\|$" avg_configfile

Or

Code:
grep -w 'Recalculation|147|' avg_configfile

# 5  
Old 08-23-2007
Quote:
Originally Posted by koti_rama
Hi all


How can i find Exactly line using grep.
my input file:
avg_configfile:
Recalculation Dates|4|
Recalculation|147|

I tryed like;
grep ^"Recalculation" avg_configfile

out put;
Recalculation Dates|4|
Recalculation|147|

But i want second line avg_configfile.i.e Recalculation|147| only.
please help me on this.
grep -w recalculation\|.*\| inputfile
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

2. Linux

How to search multiple word using grep command?

How to search multiple word using grep command for example i want to reserch ANJ001 AA Using ridiculous font, size, and color changes instead of normal space separated text and CODE tags obfuscates what you are trying to do and makes it difficult for volunteers who may want to help you solve... (1 Reply)
Discussion started by: na.dharma
1 Replies

3. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

4. Shell Programming and Scripting

Command to grep a word and print the whole line splitted into many

Hi, I need to search a word in the java file. Assume the line in the java file is, (the line was splitted into 3 lines) 1.operationContext.sendFeedback(2.FeedbackType.ERROR, null, "Input is empty.", "Input Details: pr 3.ovide Valid pair(s): "+pairType); When i grep for the word... (6 Replies)
Discussion started by: tulasiram
6 Replies

5. UNIX for Dummies Questions & Answers

find with grep command

Hi, I'm using the below command to search the files with the patterns given below. Created a file "searchtest.sh" with all the patterns. The below find command retrieves the file "AB940Insert.xml" also which shouldn't be in the desired output. Any help to fine tune the find command and to... (1 Reply)
Discussion started by: venkatesht
1 Replies

6. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

7. UNIX for Dummies Questions & Answers

Can grep command return word instead of complete line

Hi Is there any way GREP command can return word and not complete line. My file has following data: Hello Everyone I am NitinrajSrivastava Hi Friends Welcome VrajSrivastava I am using grep 'raj' which is returning me complete line.However I want only the word having keyword 'raj'. Required... (11 Replies)
Discussion started by: dashing201
11 Replies

8. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

9. UNIX for Dummies Questions & Answers

Searching mutiple word - Tuning grep command

Hi all, I have a log file which is more than 1GB, i need to take count from the log file for two strings. i am using the below command but it take a long time to excetue, i need to tune this. Please help me cat /logs/gcbs/gcbsTrace.log | grep -i "ViewStatementBusinessLogic" | grep -c -i... (8 Replies)
Discussion started by: senthilkumar_ak
8 Replies

10. UNIX for Dummies Questions & Answers

Find command with Grep

I need to find for a particular string in my /opt file system. find . -exec grep "10000" {} \; I tried this command, it works ok but I want not to search in the logs folder I have in my filesystem as it takes lot of time. SO can I exclude one or more than on directory or sub directories from... (10 Replies)
Discussion started by: venu_nbk
10 Replies
Login or Register to Ask a Question