The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find a count of a word within a file bd_joy Shell Programming and Scripting 9 07-14-2008 09:29 AM
option of grep for counting exact word ?? maddy Linux 3 06-17-2008 08:55 AM
find a word in a file, and change a word beneath it ?? vikas027 Shell Programming and Scripting 2 02-13-2008 04:23 PM
how to find a word repeated in a file gurukottur UNIX for Dummies Questions & Answers 4 08-24-2006 04:53 AM
how to find the exact pattern from a file? surjyap Shell Programming and Scripting 7 12-05-2005 09:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-20-2008
Jeevan Salunke Jeevan Salunke is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 6
Question Find Exact word in file

Hi ALL,

I want to search one string “20 “ i.e 20 with space.
But my file where I am searching this “20 “ contain some data like

120 before image file truncated
220 Reports section succeeded
20 Transaction database .prd stopped
220 Reports section completed.

When I search for the string “20 “ it give me all data like

120 before image file truncated
220 Reports section succeeded
20 Transaction database .prd stopped
220 Reports section completed.

I want output only this line.

20 Transaction database .prd stopped

I don’t want other lines.
Please suggest some code. I am using Ksh.
  #2 (permalink)  
Old 09-20-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Code:
grep '^20 ' myfile
  #3 (permalink)  
Old 09-20-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
to search only 20

Code:
$ grep '\<20\>' file
  #4 (permalink)  
Old 09-23-2008
Jeevan Salunke Jeevan Salunke is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 6
grep '^20 ' myfile
this code perfectly work as i want.

Thanks jim.
  #5 (permalink)  
Old 09-20-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
Jaduks
I think he wants only 20 at the start of a line - your regex finds the word 20 anywhere on the line.
  #6 (permalink)  
Old 09-20-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
true. Thanks :-)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0