Solved

script to add a line to a file

Posted on 2011-09-09
4
227 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:mmercaldi
  • 2
4 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36513333
mmercaldi,

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

Patrick
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 36513558
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.

~bp
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 36514211
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.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36515419
Thanks for the point...

Sorry for jumping in with speculative answer bill / patrick !
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running Visio Macro from VBS File 3 79
How do I delete 2 44
Script is being strange 8 70
Batch/VBscript: import massively chedule task in windows task scheduler 15 45
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question