Page 1 of 1

updating the date in an output file

Posted: 27 Mar 2015 09:44
by technotika
FINDSTR "^%computername%$ %date%$ %username%$" < %DESKTOP% >NUL || ECHO %computername% %date% %username%>>%DESKTOP%

Hi,

Hoping for some help here. The above batch code I use as part of an install script to silently install some software and do various other things to automate the process.
%DESKTOP% is just a variable pointing to a txt file where the out put looks like "XP-4A2A79EF62D3 27/03/2015 Admin". I didn't want multiple entries of the PC name if the PC had the software re installed, so made it so that if the entry was found it didn't repeat it. However I've since found if that PC had the software reinstalled later on I'd like the date to change to the new new install date.

So ideally my log file looked like this when I left

PC-OFFICE 27/03/2015 Admin

but if the software was re-installed on a later date I'd like the same line in the log to change the date so it would be

PC-OFFICE 29/06/2015 Domain.Admin (and if it was a different user name too)

Hope that makes sense thanks !!

Re: updating the date in an output file

Posted: 27 Mar 2015 12:11
by Compo
You cannot replace a line using a batch file, what you can do is to write a new file and overwrite the old one.

This is a bit of a guess, based upon my understanding of your question, but how about:

Code: Select all

@Echo Off
SetLocal
Set "DESKTOP=install.log"
Set "MYTMP=%TEMP%\_tmp$.log"
FindStr/V "^%COMPUTERNAME%\>" "%DESKTOP%">"%MYTMP%"
>>"%MYTMP%" Echo(%COMPUTERNAME% %DATE% %USERNAME%
Sort "%MYTMP%" /O "%DESKTOP%"
Del "%MYTMP%"
What I'm doing is a single line replacement of one or more lines with a matching Computer Name.
I'm also sorting the new log file alphabetically by Computer Name.