Solved

script to add a line to a file

Posted on 2011-09-09
4
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 55

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

726 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