批处理脚本从一个文本文件的行复制到ID的另一个基地 [英] Batch script to copy lines from one text file to another base on ID
本文介绍了批处理脚本从一个文本文件的行复制到ID的另一个基地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要写一个批处理脚本这些线路从具有给定的两个ID号中的一个管道分隔的文件拷贝。
I need to write a batch script to copy those lines from a pipe-delimited file that have one of two given ID numbers.
例如,此文件:
Jack | 12 | Jacksonville
Jane | 34 | Minneapolis
这必须是硬codeD上的ID号为12和56。
因此,一个新的文本文件必须生成将包含这样的:
The ID numbers that have to be hardcoded are 12 and 56. So a new text file has to be generated will contain this:
Jack | 12 | Jacksonville
建议?
推荐答案
所有的ID匹配的12或56文件中的 IDFile.txt
将被输出到一个新文件 MatchingIDs.txt
。
All ID's matching either 12 or 56 in the file IDFile.txt
will be outputted into a new file MatchingIDs.txt
.
@echo off
setlocal enabledelayedexpansion
set line=0
for /f "tokens=2 delims=|" %%a in (IDFile.txt) do (
set num=%%a
set num=!num: =!
if !num!==12 set bool=true
if !num!==56 set bool=true
if "!bool!"=="true" call :GETLINE
set /a line+=1
set bool=false
)
:GETLINE
if not %line%==0 set skip=skip=%line%
for /f "%skip% tokens=* delims=" %%b in (IDFile.txt) do (
echo %%b >>MatchingIDs.txt
goto :BREAK
)
:BREAK
这篇关于批处理脚本从一个文本文件的行复制到ID的另一个基地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文