script to add a line to a file

I am looking for a script either batch or vb that can add a line of text to a file, but if that certain line of text is there then the script ends.

This is for windows xp and 7 computers
Who is Participating?
Steve KnightConnect With a Mentor IT ConsultancyCommented:
Agreed on above.  If it is a text / INI file type situation for instance then how about though:

@Echo off
set file=c:\program\file.ini
set line=newline for the file=1
find /i "%Line%" "%file%" || echo %line%>>"%file%"

Which says:

set the file variable to the path to the text file
set the line variable to the line to search for and add if not there
looks in the file for the line, if it isn't there then append it to the file.

Patrick MatthewsCommented:

What in particular do you need to do?  An example would be helpful :)

Bill PrewCommented:
From a BAT perspective it sounds like you could use FIND or FINDSTR to search the file for something unique to the line to be added, and then if it's not found "add" the new line.  But we'd need a bit more detail on what the file is, what the new line looks like, where it is to be added to the file, etc.

Steve KnightIT ConsultancyCommented:
Thanks for the point...

Sorry for jumping in with speculative answer bill / patrick !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.