Results 1 to 2 of 2
Hello!
Please, help me to write such script (bash script) .
I have some text file with name filename.txt
I must check if this file contains string "test-string-first", I must ...
- 04-17-2011 #1Just Joined!
- Join Date
- Apr 2011
- Posts
- 2
Find string in text file (bash script)
Hello!
Please, help me to write such script (bash script).
I have some text file with name filename.txt
I must check if this file contains string "test-string-first", I must cut from this file string which follows string "keyword-string:" and till first white-space and save it to some variable.
For example. File:
This file contains "test-string-first" and I need to get 123456321-net string (between "keyword-string:" and first space)PHP Code:PHP Code:
Start 15022011 Eng 12-3-42
SN1232324422 11 test-string-first
SN322211 securities
HH keyword-string:123456321-net mark (11-22)
and i want to have such code structure:
help me pls to change check_exists_of('test-string-first','filename.txt') and MYVAR = awk .... filename.txt statements to the correct.PHP Code:if (check_exists_of('test-string-first','filename.txt') then
MYVAR = awk .... filename.txt
echo $MYVAR
else
echo 'file doesn't contain '''test-string-first'' string!'
fi
- 04-18-2011 #2
I would provide some hints . I hope you can take it from there.
grep command is used to search for text.
like
ret=`grep "searchtext" Filename.txt`
If grep command pass (ie it found "searchtext" ) $? will be equal to zero.- 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
-------------------


Reply With Quote