search pattern if found do not add if not found add
Hi Colucix,
I am trying to get a result out of this but fails please help. Have two files /tmp/1 & /tmp/hosts. /tmp/1 IP=123.456.789.01 WAS_HOSTNAME=abcdefgh.was.tb.dsdc /tmp/hosts 123.456.789.01 I want this result in /tmp/hosts if hostname is already there dont want duplicate entry. This is wrong 123.456.789.01 abcdefgh.was.tb.dsdc abcdefgh.was.tb.dsdc This is correct 123.456.789.01 abcdefgh.was.tb.dsdc Trying with this: if grep abcdefgh.was.tb.dsdc /tmp/hosts; then . /tmp/1 && sed -i "s/^$IP\(.*\)$/$IP\1 $WAS_HOSTNAME/" /tmp/hosts; fi Thanks in advance |
The if grep abcdefgh.was.tb.dsdc /tmp/hosts part checks if the string is present, you need to know if the string is not present.
Try this: Code:
if ! grep abcdefgh.was.tb.dsdc /tmp/hosts |
All times are GMT -5. The time now is 02:46 AM. |