[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: Script to add line to file if it doesn't exist



> I want a script that will read the file and look for the name 
> "fred", and if it's found, leave the file alone, but if it's 
> not found, to add the name "fred" to the bottom of the file.

No need for awk/sed. Something like this should work.

#!/bin/bash
i=`grep fred FILENAME.TXT | wc -l`
if [ $i == "0" ]
then
        echo "fred" >> FILENAME.TXT
fi

> 
> Any help appreciated. Thanks!
> 
> -- 
> Kent West        <")))><
> http://kentwest.blogspot.com
> 
> 
> 
> --
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact 
> listmaster@lists.debian.org
> Archive: [🔎] 4BBCE69D.3040308@acu.edu">http://lists.debian.org/[🔎] 4BBCE69D.3040308@acu.edu
> 
> 


Reply to: