Find the answer to your Linux question:
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 ...
  1. #1
    Just 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.

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,100
    grep can do it.
    Code:
    man grep
    You must always face the curtain with a bow.

  3. #3
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568
    In case if you searching from within vi editor - follow these steps

    vi filename.txt
    and then type
    :set hls is
    Now
    /searchtext
    will highlight the occurance of searchtext in filename.txt.
    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
    -------------------

  4. #4
    Just 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.

  5. #5
    Just 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

  6. #6
    Linux Enthusiast Mudgen's Avatar
    Join Date
    Feb 2007
    Location
    Virginia
    Posts
    623
    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:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...