从多个文件中提取所有行 [英] Extracting all lines from multiples files
本文介绍了从多个文件中提取所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个文件:
- 第一个文件是ID列表
- 第二个文件是源字符串
- 第三个文件由目标字符串组成。
File 1
3952276-0-1
3952276-0-2
3952276-0-3
3952276-0-4
3952276-0-5
3952276-0-6
3952276-0-7
3952276-0-8
3952276-0-9
3952276-0-10
File 2
source-string1
source-string2
source-string3
source-string4
source-string5
source-string6
source-string7
source-string8
source-string9
source-string10
File 3
target-string1
target-string2
target-string3
target-string4
target-string5
target-string6
target-string7
target-string8
target-string9
target-string10
我想要像csv中的结果文件像,除非目标字符串与源字符串相同,不要复制 在。 ..如果与源
I want a result file in csv like with the exception if the the target-string is the same of source string, DO NOT COPY in ""... leave the "" of target-string empty if it's the same of source
"3952276-0-1","source-string1","target-string1"
"3952276-0-2","source-string2","target-string2"
"3952276-0-3","source-string3","target-string3"
提前Thx
推荐答案
@echo off
setlocal EnableDelayedExpansion
rem File 1 is read with the FOR command
rem File 2 and File 3 are read via standard handles 3 and 4, respectively
3< file2.txt 4< file3.txt (for /F "delims=" %%a in (file1.txt) do (
set /P "source=" <&3
set /P "target=" <&4
if "!target!" neq "!source!" (
echo "%%a","!source!","!target!"
) else (
echo "%%a","!source!",""
)
)) > output.txt
有关用于读取多个文件的方法的详细信息,请参阅此信息。
For further details on the method used to read several files, see this post.
这篇关于从多个文件中提取所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文