I am trying to get a script working to extract a specific line out of multiple text files at once. I have the script that will extract the line out of the text but I cannot get it to do this to multiple files.
What I have is an inventory file for each computer at my facility. I'm trying to extract like 16 which has the user's name so each file will have a different value on line 16 but it's always line 16.
Example file I'm trying to extract from:
<HTML>
<BODY>
<center>
<table border=1>
<tr>
<th>Full Name</th>
<th>UserID</th>
<th>IP Address</th>
<th>Make</th>
<th>Model</th>
<th>Serial Number</th>
<th>Default Printer</th>
</tr>
<tr>
<td>John Doe</td>
<td>USERNAME</td>
<td> 1. 1. 1.1
</td>
<td>Hewlett-Packard
</td>
<td>HP Compaq 8000 Elite SFF PC
</td>
<td>SERIALNUMBERX
</td>
<td>Microsoft XPS Document Writer
</td>
</tr>
</table></font>
<br />
Inventory taken on 2015/11/24 at 07:43:14. </center>
</BODY>
</HTML>
I'm wanting the script to extract the information to a text file so I can put it into a spreadsheet basically.
Here's my script so far. (The toop part I believe is the issue - the FOR
command specifically) Sorry for my scripting ignorance. Trying to learn as I go.
@echo off &setlocal
setlocal EnableDelayedExpansion
set filename=\\computername\c$\users\username\desktop\pcs.txt
for /F "tokens=*" %%a in ('type %filename%') do (
set file=%%a.html
)
set /a from=16
set /a till=16
for /f %%i in ('type "%file"^|find /v /c ""') do if %till% gtr %%i set /a till=%%i
set /a skip=from-1
setlocal EnableDelayedExpansion
<"!file!" (
for /l %%i in (1 1 %skip%) do set /p "="
for /l %%i in (%from% 1 %till%) do (
set "ln="
set /p "ln="
echo(!ln! >> c:\users\username\desktop\extracted.txt
)
)
endlocal
pause
My pcs.txt file is setup like this:
pc1
pc2
pc3
I ended up using psexec to run the file on each computer instead.
PSEXEC command:
psexec @\\server\c$\pcs.txt -u domain\username -p password cmd /c \\server\c$\extract.bat
Always line 16?