简体   繁体   English

使用DOS Windows命令行FOR编辑txt文件

[英]edit a txt file with DOS Windows command line FOR

After using dos commands to collect data and ' findstr ' and 'for ', I now have a data file that looks like this: 使用dos命令收集数据以及'findstr'和'for'之后,我现在有了一个数据文件,如下所示:

 string9
 40%
 string1
 55%
 string12
 78%
 ...at least 9 strings more strings with their associated percentages

I need the data to format to this: 我需要将数据格式化为:

string9  40%
string1 55%
string12 78% 

I know the FOR command is probably what I need. 我知道FOR命令可能是我需要的。 If i could pass a backspace to the begining of every other line, that would be nice. 如果我可以在所有其他行的开头都使用退格键,那就太好了。

Here is code that got me to this point. 这是使我明白这一点的代码。

@echo off
netsh wlan show networks mode=BSSI > rssifile.txt
findstr /V "Channel Interface There Network Authentication Encryption BSSID Radio Channel rates"       rssifile.txt >rssifil1.txt
if exist closer.txt del closer.txt /Q
if exist closer01.txt del closer01.txt /Q
if exist clos0001.txt del clos0001.txt /Q
for /F "usebackq tokens= 1,2 delims=:" %%G IN ("rssifil1.txt") DO echo %%H >>closer.txt 
more +1 closer.txt > closer01.txt

It is a work in progress. 这是一项正在进行的工作。 Below is one possible approach I am toying with: 以下是我正在尝试的一种可能的方法:

rem pseudo code for sorting and collecting RSSI %
 set nayme="nayme0"
 set /A Cnt=1
  If Cnt < 13 
 for /F "tokens" %%a in (%InFile%) do (
 echo nayme %%a >>  clos0001.txt
 if nayme="nayme0"
   nayme=nayme1
   goto far  

  if nayme="nayme1"
   nayme=nayme2
   goto far  

  if nayme="nayme1"
   nayme=nayme2
   goto far  

  if nayme="nayme1"
   nayme=nayme2
   goto far  

 :far

This approach, psuedo coded above involves putting the 12 RSSI names I am monitoring in sequence as well. 上面用psuedo编码的这种方法还涉及将我正在监视的12个RSSI名称依次放置。

The file would look like this: 该文件如下所示:

nayme0 77%
nayme1 84%
nayme2 88%    ...

The end result would be a one line file that would be appended to another file. 最终结果将是一个单行文件,该文件将附加到另一个文件。

Collecting the 12 percentages in order would eliminate listing the nayme / SSID. 按顺序收集12个百分比将消除列出nayme / SSID。 The line in the text file would look like this: 文本文件中的行如下所示:

3:14 PM  57% 67% 97% 36% 47% 88% 95% 22% 85% 77% 33% 79%

Here is my suggestion for your initial question. 这是我对您的第一个问题的建议。

@echo off
setlocal enabledelayedexpansion
set line=
for /f "tokens=1,2 delims=:" %%i in ('netsh wlan show networks mode^=BSSID ^|findstr "^SSID Signal"') do (
    echo %%i|find "SSID" >nul && (echo(!line! & set "line=%%j") || (set "line=!line!%%j" )
    )
echo %line%

rest tomorrow - it's quite late now here... 明天休息-现在已经很晚了...

Questions: Do you watch a known list or should it be dynamic? 问题:您观看已知列表还是动态列表? What do you do if there is a week connection to one of them and you loose it from time to time? 如果其中一个人有一个星期的连接并且不时失去连接该怎么办?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM