小编ran*_*ham的帖子

尝试使用 AWK 从一个文件中基于另一文件查找完整的字符串值

您好,我有 2 个文件,第一个文件包含一些值,例如

powershell
vectormaps
JuniperSA
Run Code Online (Sandbox Code Playgroud)

第二个文件包含值 和 ID

appid uid
SplunkforSnort 340
powershell 610
vectormaps 729
JuniperSA 826
postfix 933
SplunkforJuniperSRX 929
TA-barracuda_webfilter 952
TA-dragon-ips 954
dhcpd 392
Run Code Online (Sandbox Code Playgroud)

因此,我尝试使用 AWK 运行 while 循环来获取值及其相应的 ID,但输出文件似乎正在写入其他内容。这就是我尝试运行 while 循环的方式。

while read $line;
do
awk '/'$line'/ {print $0}' file2.csv > new
done < file1
Run Code Online (Sandbox Code Playgroud)

我的预期输出应该是

powershell 610
vectormaps 729
JuniperSA 826
Run Code Online (Sandbox Code Playgroud)

但我的输出是

appid uid
SplunkforSnort 340
powershell 610
vectormaps 729
JuniperSA 826
postfix 933
SplunkforJuniperSRX 929
TA-barracuda_webfilter 952
TA-dragon-ips 954
dhcpd 392
Run Code Online (Sandbox Code Playgroud)

似乎什么也没有发生。我在这里缺少什么?

awk read

2
推荐指数
1
解决办法
1528
查看次数

标签 统计

awk ×1

read ×1