bat脚本中For /f 中的Delims、Tokens、skip、eol、goto使用总结

aaa.txt 内容如下:
1、饶天亮-玫瑰爱人.wma
2、高一首-我不愿错过.mp3
3、黃凱芹-傷感的戀人.MP3
4、黄灿-黄玫瑰.lrc
5、黎姿-如此这般的爱情故事.mp3

---------------------------------------------------------

1,逐行打印出全部内容
@echo off
for /f %%i in (aaa.txt) do echo %%i
pause>nul

-------------------------

2,只取每行“、”号前面的内容 delims默认提取第一列
@echo off
for /f "delims=、" %%i in (aaa.txt) do echo %%i
pause>nul

-------------------------

3,用减号“-”做分隔符
@echo off
for /f "delims=-" %%i in (aaa.txt) do echo %%i
pause>nul

-------------------------

4,用点号“.”做分隔符
@echo off
for /f "delims=." %%i in (aaa.txt) do echo %%i
pause>nul

-------------------------

5,定义多个分隔符“、-.”
@echo off
for /f "delims=、-." %%i in (aaa.txt) do echo %%i
pause>nul
每行被三个分隔符拆分成4段,默认只会显示第一段,

-------------------------

6,想取第2段,则tokens=2,以此类推
@echo off
for /f "tokens=2 delims=、-." %%i in (aaa.txt) do echo %%i
pause>nul

-------------------------

7,如果想取序号(1)和歌曲名(3)怎么写:{提取多列}
@echo off
for /f "tokens=1,3 delims=、-." %%i in (aaa.txt) do echo %%i%%j
pause>nul

-------------------------


8,如果想取2-4怎么写:{提取连续多列}
@echo off
for /f "tokens=2-4 delims=、-." %%i in (aaa.txt) do echo %%i%%j%%k
pause>nul

-------------------------

9,忽略XX开头的行“3”开头的eol=3 忽略以某字符开头的行
@echo off
for /f "eol=3 delims=、-." %%i in (aaa.txt) do echo %%i
pause>nul

-------------------------

10,skip=n 忽略前N行
@echo off
for /f "skip=4" %%i in (aaa.txt) do echo %%i
pause>nul

-------------------------

11,综合应用。查询并提取本机“无线网络连接 2”的网关
@echo off
for /f "skip=5 tokens=2 delims=:" %%i  in ('netsh interface ip show address "无线网络连接 2"') do set "zt=%%i" &goto :next
:next
echo 本机无线网关为:%zt%
pause>nul

说明:此处无需指定分隔符,比如:delims=: ,因为制表符为默认分隔符,而:不是,如果指定:为分隔符,
则制表符会被忽略,则提取的网关前面有一长串空格(制表符),需自行去空格处理。

-------------------------

12,bat 修改代理服务器
@echo off
title 自动设置代理服务器
 
echo 正在设置代理服务器……
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "192.168.43.202:18080" /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "" /f
 
echo 正在刷新设置……
ipconfig /flushdns

pause

效果:

参考这里:https://www.cnblogs.com/leilong/p/8555027.html

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页