使用包含第x列的3个文件中的数据,我需要在列帐户中输出数据 [英] Using the data in 3 files containing column x I need to output the data in column account
问题描述
我有3个txt文件,分别是file1,file2,file3,其中包含用"|"分隔的数据 我需要过滤在columnx中仅包含"1"的所有行,并在"account"列中打印值
I have a 3 txt files namely file1 , file2 , file3 containing data separated with "|" I need to filter all the lines that only having "1" in columnx and print the value in the column "account"
file1.txt
file1.txt
line|account|column3|columnx
line1|111111|jahadkadaldabndal|1
line2|2323413341|adajkadadbjkqqweq|0
line3|21122|adaieaqelqq|0
line4|236521|jadad|1
file2.txt
file2.txt
line|account|column3|columnx
line1|1117831|jahadkadaldabndal|1
line2|23234178841|adajkadadbjkqqweq|1
line3|21122|adaieaqelqq|0
line4|236526|jadad|1
file3.txt
file3.txt
line|account|column3|columnx
line1|1113333|jahadkadaldabndal|1
line2|232341335|adajkadadbjkqqweq|1
line3|21124|adaieaqelqq|1
line4|236523|jadad|1
输出应如下所示:
111111
236521
1113333
236523
21124
232341335
1117831
23234178841
236526
我有一个代码,但仅在线获取一个文件txt.
i have a code but online for one file txt only.
powershell -nop -c "(import-csv .\*.txt -del '|'|? columnx -eq 1).account"
我仍在弄清楚应该使用什么.我真的是新手,任何人都可以教我或给我一些代码,以便我能完成这一步谢谢你.
I'm still figuring out what I should use I'm really new in this stuff can anyone teach me or give me some code so that I can finish this one thank you.
推荐答案
@echo off
for %%A in (*.txt) do for /F "usebackq skip=1 tokens=2,4 delims=|" %%A in ("%%~A") do (
for %%B in (%%B) do if %%B EQU 1 echo %%A
)
pause
for %%A in (*.txt)
遍历每个文本文件.通配符可以适当设置,例如file*.txt
或适合您情况的任何内容.
for %%A in (*.txt)
iterates through each text file. the wildcard can be set as appropriate e.g. file*.txt
or whatever as appropriate to your case.
for /F "usebackq skip=1 tokens=2,4 delims=|"
读取父级FOR
传递的每个文件,逐行处理每个文件,并从每一行(即account和columnx)中获取令牌2和4.如果文件包含标题line|account|column3|columnx
(如果未删除skip=1
for /F "usebackq skip=1 tokens=2,4 delims=|"
reads each file that is passed by the parent FOR
, process each file line by line takes tokens 2 and 4 from each line (that is account and columnx). skip=1
skips the first line if the file contains the header line|account|column3|columnx
if not remove skip=1
for %%B in (%%B)
将从最后一个标记(columnx)中删除所有前导/后跟空格,以便与1
进行比较,以确保如果最后一列中包含空格.
for %%B in (%%B)
is to remove any leading/trailing spaces from the last token (columnx) for comparison against 1
to be correct if last the column contains spaces.
这篇关于使用包含第x列的3个文件中的数据,我需要在列帐户中输出数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!