How to use if/else logic in sed/awk

In sed and/or awk, how would I formulate an if/else logic to skip a command if a specific text already exist in a file?

I am getting multiple entries in a text file when the script is executed again.

awk will work on all lines of a file by default, or you can use a regular expression and have it only act on matching (or non-matching) lines. e.g:

$ cat testit.txt
One
Two
Three
Four
Five
Six
Seven
Eight
Nine
Ten
Eleven
Twelve

$ awk '/i/ {print $0}' testit.txt
Five
Six
Eight
Nine

$ awk '!/i/ {print $0}' testit.txt
One
Two
Three
Four
Seven
Ten
Eleven
Twelve

Or if you need to check the whole file for the existence of some expression first, and then conditionally execute some commands, you could try something like

if grep -l "Six" testit.txt >/dev/null
then
print Text was found
else
print Text was not found
fi

Have a Unix Problem
Do you have a UNIX Question?

Books About Unix
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Unix Home: Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.