Solved

script to add a line to a file

Posted on 2011-09-09
4
208 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 51

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now