Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, I want to write some code to search for a specific string in a text file, but without using grep command. Thanks....
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    3

    find a string in a file without using grep


    Hi, I want to write some code to search for a specific string in a text file, but without using grep command.
    Thanks.

  2. #2
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    google: awk

  3. #3
    Just Joined!
    Join Date
    Oct 2010
    Posts
    3
    well, thank you very much, but I want to write C code to do the job...
    How can I write the code to search for e.g. the word "test" in the file "myfile.txt" without using grep command...

  4. #4
    Just Joined! sixdrift's Avatar
    Join Date
    Jan 2007
    Location
    In and around and about Cary, NC
    Posts
    44
    This sounds like a homework question. Think it through. Run through the searching process manually on paper. Essentially you want to do just what a human would do, look for the pattern starting with the first character, then look at each subsequent character. If you get a mismatch, then start the pattern again.

  5. #5
    Just Joined!
    Join Date
    Oct 2010
    Posts
    3
    well yes it is a homework...You mean that there is not something special in linux to search a string in a file, like for example "sort " command.
    So I have to hardcode it...?

  6. #6
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    Well even if there is it is against the forum rules to ask homework questions

Posting Permissions

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