Find the answer to your Linux question:
Results 1 to 5 of 5
I'm a newbie. So, please help me out of this problem. I'm trying to read certain words from a txt file into my script. Here is an example example.txt //my ...
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    14

    How can i read certain words in a txt file into my script ?

    I'm a newbie. So, please help me out of this problem. I'm trying to read certain words from a txt file into my script. Here is an example

    example.txt //my txt file name
    person name age sex //this is the data which will b in my txt file
    medicine record hospital date // this is also

    what i wanna do is i wanna read " person " and " medicine" only 2 words from that txt file and make a decision whether "person " and " medicine" is already in the text file or not. How can i retrive that information that specific words and test it in my script file ? Please help me out of this . It's just way over my head. I've tried sed , awk , and filter but still i dunno so far.

    Thanks in advance

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    When does your instructor say this assignment is due?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Posts
    14
    ok he said this week Friday is the due date. So, i'm sort of nervous. Please help me out of this. What i'm asking for is not a complete source code. just direct me to the right command or website and i'll try to get it on my own. Please just direct me to the right command.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    If you have two specific words, and you want to know whether either of them is in a given text file, grep is the tool you want.

    At the command line, do this:
    Code:
    man grep
    If the man page for grep is not installed on your system, google this:
    Code:
    man grep linux
    Hope this helps. Good luck!
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Jan 2008
    Posts
    14
    ah ! Thanks for that . I completely forgot the grep command . This is what i'm trying to do . Gosh ! how foolish ! I didn't realize that i can do that with grep . Thanks wje_lf

    if [ -f $1 -o ! $1 ]
    then
    echo "TYPE IN THE FILE NAME OR FILE IS ALREADY EXISTED"
    fi
    totalLine=`more schemas.txt | wc -l`
    for (( i=0 ; i < $totalLine ; i++))
    {
    endLine=$totalLine
    targetID=`tail +$endLine schemas.txt | head -n1`
    echo $targetID
    endLine=endLine-1
    }

Posting Permissions

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