add line to a file ONLY if it is not in file already

Assuming you want it at the end of the file:

LINE="nohup java -jar /mnt/fusion/nfs/labStats/LabInfoAutoLog.jar > /dev/null &"
FILE=/etc/rc.d/rc.local
grep -q "$LINE" "$FILE" || echo "$LINE" >> "$FILE"

one option is two steps:

grep -q "yourline" /path/file||sed -i '/..place../ a \the line' file

also possible to do with awk,

save all lines in array, during saving if the line was found, exit. otherwise, add the line in END{} block to the right place.

P.S. You didn't tell in the file, where to add that line.

Tags:

Linux

Grep

Sed