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


i want add following line:

nohup java -jar /mnt/fusion/nfs/labstats/labinfoautolog.jar > /dev/null & 

to end of file /etc/rc.d/rc.local if not exist.

how can linux command line? assume grep or sed work, not familiar enough either work. right use echo, keeps adding on , on again.

assuming want @ end of 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" 

Comments