Results 1 to 6 of 6
Hallo!I am using Oracle Enterprise Linux version 4 update 7.
Sometimes I have to access large files with thousands of lines in them and I would like to locate a ...
- 07-06-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 3
How to locate words in a file
Hallo!I am using Oracle Enterprise Linux version 4 update 7.
Sometimes I have to access large files with thousands of lines in them and I would like to locate a particultar word. e.g.
vi /etc/passwd.
The contents of file passwd are displayed.I want to find a username of joe assuming the passwd file is 2000 lines long.
I would like to use a linux command that will locate joe and highlight in the passwd file as to where word joe is.
Is there a linux command that can do this?
Thanks.
- 07-06-2010 #2
grep can do it.
Code:man grep
You must always face the curtain with a bow.
- 07-06-2010 #3
In case if you searching from within vi editor - follow these steps
and then typevi filename.txt
Now:set hls is
will highlight the occurance of searchtext in filename.txt./searchtext
Press n to move to next occurance of the word.- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-06-2010 #4Just Joined!
- Join Date
- Jun 2007
- Posts
- 36
Hi Joey41,
if you are sure about the file and parameter you are searching then you can search simply by using grep.
Ex :
#grep /etc/passwd | grep joe
#cat /etc/passwd | grep joe
if you want some more interaction then use,
#grep --color joe /etc/passwd
otherwise you can open a file using vim,
vim /etc/passwd and
you can search the specify string by / notation in the file.
I hope this will solve your things,if you are ok with this just mark this post as solved.
- 07-07-2010 #5Just Joined!
- Join Date
- Jun 2007
- Posts
- 16
I'd do something like Lakshmipathi stated, but just use:
/set ic is
the ic is to ignore case so you can find Joe or joe
- 07-07-2010 #6
In case you haven't turned in your homework yet, given the syntax of /etc/passwd, to find an account named "joe" in vi you'd use:
/^joe:


Reply With Quote