从文本脚本中提取特定行 [英] Extract specific line from text script
问题描述
我正在尝试使一个脚本能够一次从多个文本文件中提取特定行.我有将脚本从文本中提取出来的脚本,但是我无法通过脚本将其提取到多个文件中.
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.
我所拥有的是我所在工厂中每台计算机的清单文件.我正在尝试提取类似16的名称,该名称具有用户名,因此每个文件的第16行将具有不同的值,但始终为16行.
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.
到目前为止,这是我的脚本. (我认为是问题的主要部分-具体是FOR
命令)很抱歉,我对脚本的了解不够.尝试边走边学.
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
我的pcs.txt文件的设置如下:
My pcs.txt file is setup like this:
pc1
pc2
pc3
推荐答案
我最终使用psexec在每台计算机上运行文件.
I ended up using psexec to run the file on each computer instead.
@echo off &setlocal
setlocal EnableDelayedExpansion
set "file=\\server\public\is\kixtartlogs\%computername%.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(%computername% !ln! >> \\computername\c$\users\username\desktop\extracted.txt
)
)
endlocal
PSEXEC命令:
psexec @\\server\c$\pcs.txt -u domain\username -p password cmd /c \\server\c$\extract.bat
PSEXEC command:
psexec @\\server\c$\pcs.txt -u domain\username -p password cmd /c \\server\c$\extract.bat
这篇关于从文本脚本中提取特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!