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 ...
- 01-29-2008 #1Just 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
- 01-29-2008 #2
When does your instructor say this assignment is due?
--
Bill
Old age and treachery will overcome youth and skill.
- 01-30-2008 #3Just 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.
- 01-30-2008 #4
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:
If the man page for grep is not installed on your system, google this:Code:man grep
Hope this helps. Good luck!Code:man grep linux
--
Bill
Old age and treachery will overcome youth and skill.
- 01-30-2008 #5Just 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
}


Reply With Quote