?
Solved

script to add a line to a file

Posted on 2011-09-09
4
Medium Priority
?
247 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 93

Expert Comment

by:Patrick Matthews
ID: 36513333
mmercaldi,

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

Patrick
0
 
LVL 56

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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

743 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