View Full Version : Edit a TXT file via batch file...


=?Utf-8?B?TWlrZQ==?=
02-24-2004, 05:31 AM
I need to be able to print out an output file which will contain a user id and pw... I need an automated process to edit these out entirely via the command prompt / batch file but can't seem to figure out how.

I can easily search for the string.. FINDSTR "rootadmin" or FIND "rootadmin" but I can't delete any strings in the text file. Is it possible to do what I need to do

Thanks
Mike

Phil Robyn [MVP]
02-24-2004, 08:19 AM
Mike wrote:
> I need to be able to print out an output file which will contain a user id and pw...
> I need an automated process to edit these out entirely via the command prompt / batch
> file but can't seem to figure out how.
>
> I can easily search for the string.. FINDSTR "rootadmin" or FIND "rootadmin" but I can't
> delete any strings in the text file. Is it possible to do what I need to do?
>
> Thanks!
> Mike

What kind of output file? Maybe messages from an FTP session? :-) Whose userid and
password? Yours? Someone else's?

If the output file is in a particular predictable format (e.g., messages from an FTP
session), then it's pretty easy to remove the userid and password without having to
know what the userid and password are. If the output file is not in a predictable
format, and you don't know what the password is (because it's not yours), then it
will be pretty tough to remove the password, as you cannot search for something that
you do not know.

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Phil Robyn [MVP]
02-24-2004, 08:19 AM
Mike wrote:
> I need to be able to print out an output file which will contain a user id and pw...
> I need an automated process to edit these out entirely via the command prompt / batch
> file but can't seem to figure out how.
>
> I can easily search for the string.. FINDSTR "rootadmin" or FIND "rootadmin" but I can't
> delete any strings in the text file. Is it possible to do what I need to do?
>
> Thanks!
> Mike

What kind of output file? Maybe messages from an FTP session? :-) Whose userid and
password? Yours? Someone else's?

If the output file is in a particular predictable format (e.g., messages from an FTP
session), then it's pretty easy to remove the userid and password without having to
know what the userid and password are. If the output file is not in a predictable
format, and you don't know what the password is (because it's not yours), then it
will be pretty tough to remove the password, as you cannot search for something that
you do not know.

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

=?Utf-8?B?TWlrZQ==?=
02-24-2004, 11:21 AM
Hey Phil..
The user id and pw will be predictable every time...good point! ;) However, I am using a telnet wrapper which is is going to record an automated session where I will have a couple values returned. This entire session is going to be then output to a txt file.
As far as I know during this session I cannot turn off and then turn back on the logging to the txt file. It logs everything.
So... how can I have a batch file go to this txt output file and have it automatically delete / or modify the account/pw info??
Thanks
Mike

=?Utf-8?B?TWlrZQ==?=
02-24-2004, 11:21 AM
Hey Phil..
The user id and pw will be predictable every time...good point! ;) However, I am using a telnet wrapper which is is going to record an automated session where I will have a couple values returned. This entire session is going to be then output to a txt file.
As far as I know during this session I cannot turn off and then turn back on the logging to the txt file. It logs everything.
So... how can I have a batch file go to this txt output file and have it automatically delete / or modify the account/pw info??
Thanks
Mike

Matthias Tacke
02-24-2004, 01:01 PM
"=?Utf-8?B?TWlrZQ==?=" wrote:

>Hey Phil...
>The user id and pw will be predictable every time...good point! ;)
>However, I am using a telnet wrapper which is is going to record an
>automated session where I will have a couple values returned. This
>entire session is going to be then output to a txt file. As far as I
>know during this session I cannot turn off and then turn back on the
>logging to the txt file. It logs everything. So... how can I have a
>batch file go to this txt output file and have it automatically delete
>/ or modify the account/pw info??? Thanks, Mike

Hello Mike,
You could use
findstr /V "Account Password" logfile >changedlog
to omit the lines from the file.
And delete lofile afterwards.
HTH
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm

Matthias Tacke
02-24-2004, 01:01 PM
"=?Utf-8?B?TWlrZQ==?=" wrote:

>Hey Phil...
>The user id and pw will be predictable every time...good point! ;)
>However, I am using a telnet wrapper which is is going to record an
>automated session where I will have a couple values returned. This
>entire session is going to be then output to a txt file. As far as I
>know during this session I cannot turn off and then turn back on the
>logging to the txt file. It logs everything. So... how can I have a
>batch file go to this txt output file and have it automatically delete
>/ or modify the account/pw info??? Thanks, Mike

Hello Mike,
You could use
findstr /V "Account Password" logfile >changedlog
to omit the lines from the file.
And delete lofile afterwards.
HTH
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm

Michael A. Covington
02-24-2004, 04:43 PM
You could find a Windows implementation of "sed" (the popular UNIX string
editor, often used in UNIX scripts) and use that. You can call sed from the
command line with an argument saying what changes to make in the file.

There are Windows implementations of sed. Google should be able to find one
quickly.

Michael A. Covington
02-24-2004, 04:43 PM
You could find a Windows implementation of "sed" (the popular UNIX string
editor, often used in UNIX scripts) and use that. You can call sed from the
command line with an argument saying what changes to make in the file.

There are Windows implementations of sed. Google should be able to find one
quickly.

Phil Robyn [MVP]
02-24-2004, 06:02 PM
Mike wrote:
> Hey Phil...
> The user id and pw will be predictable every time...good point! ;) However, I am using a
> telnet wrapper which is is going to record an automated session where I will have a couple
> values returned. This entire session is going to be then output to a txt file.
> As far as I know during this session I cannot turn off and then turn back on the logging
> to the txt file. It logs everything.
> So... how can I have a batch file go to this txt output file and have it automatically delete
> / or modify the account/pw info???
> Thanks,
> Mike

Post an actual example of the file or part of the file containing
the userid and password that is to be removed. Remember, if the
actual userid and password to be removed are not known, it will not
be possible to locate them using FIND or FINDSTR, because you will
not know what to specify as search arguments.

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Phil Robyn [MVP]
02-24-2004, 06:02 PM
Mike wrote:
> Hey Phil...
> The user id and pw will be predictable every time...good point! ;) However, I am using a
> telnet wrapper which is is going to record an automated session where I will have a couple
> values returned. This entire session is going to be then output to a txt file.
> As far as I know during this session I cannot turn off and then turn back on the logging
> to the txt file. It logs everything.
> So... how can I have a batch file go to this txt output file and have it automatically delete
> / or modify the account/pw info???
> Thanks,
> Mike

Post an actual example of the file or part of the file containing
the userid and password that is to be removed. Remember, if the
actual userid and password to be removed are not known, it will not
be possible to locate them using FIND or FINDSTR, because you will
not know what to specify as search arguments.

--
Phil Robyn
Univ. of California, Berkeley

u n z i p m y a d d r e s s t o s e n d e - m a i l

Torgeir Bakken (MVP)
02-25-2004, 02:23 AM
"Michael A. Covington" wrote:

> You could find a Windows implementation of "sed" (the popular UNIX string
> editor, often used in UNIX scripts) and use that. You can call sed from the
> command line with an argument saying what changes to make in the file.
>
> There are Windows implementations of sed. Google should be able to find one
> quickly.

Hi

I like the utilities on this site, it's a native Win32 port of many
GNU utilities, sed included:

http://unxutils.sourceforge.net


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter

Torgeir Bakken (MVP)
02-25-2004, 02:23 AM
"Michael A. Covington" wrote:

> You could find a Windows implementation of "sed" (the popular UNIX string
> editor, often used in UNIX scripts) and use that. You can call sed from the
> command line with an argument saying what changes to make in the file.
>
> There are Windows implementations of sed. Google should be able to find one
> quickly.

Hi

I like the utilities on this site, it's a native Win32 port of many
GNU utilities, sed included:

http://unxutils.sourceforge.net


--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter