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
$ awk '/i/ {print $0}' testit.txt
$ awk '!/i/ {print $0}' testit.txt
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
Have a Unix Problem
Books About Unix
Unix Home: Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|