Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Apr 2011
Find string in text file (bash script)
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:
Start 15022011 Eng 12-3-42
SN1232324422 11 test-string-first
HH keyword-string:123456321-net mark (11-22)
and i want to have such code structure:
if (check_exists_of('test-string-first','filename.txt') then
MYVAR = awk .... filename.txt
echo 'file doesn't contain '''test-string-first'' string!'
I would provide some hints . I hope you can take it from there.
grep command is used to search for text.
ret=`grep "searchtext" Filename.txt`
If grep command pass (ie it found "searchtext" ) $? will be equal to zero.