Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test For Value in a File

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

Could someone please give me an example of testing a file for a string and if it does not exist in it appending a new line\entry into it. I am testing for a hostname.

Thanks very much for your help!

Michael
 
man grep

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
> cat host.txt
text1
text2
text3

> cat z
cnt=`grep -ic &quot;text5&quot; host.txt`
if [ $cnt -eq 0 ]; then
echo &quot;text5&quot; >> host.txt
fi

> z
> cat host.txt
text1
text2
text3
text5
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top