这是一个文本处理问题。我有2个文件:
joeblogs
johnsmith
chriscomp
Run Code Online (Sandbox Code Playgroud)
12:00:00 (AAA) OUT: "string" joeblogs@hostname
12:00:00 (AAA) OUT: "string" joeblogs@hostname
12:00:00 (AAA) OUT: "string" johnsmith@hostname
12:00:00 (AAA) OUT: "string" joeblogs@hostname
12:00:00 (AAA) OUT: "string" chriscomp@hostname
Run Code Online (Sandbox Code Playgroud)
文件 1 包含出现在日志中的唯一用户名列表(文件 2)。
期望输出
12:00:00 (AAA) OUT: "string" USER1@hostname
12:00:00 (AAA) OUT: "string" USER1@hostname
12:00:00 (AAA) OUT: "string" USER2@hostname
12:00:00 (AAA) OUT: "string" USER1@hostname
12:00:00 (AAA) OUT: "string" USER3@hostname
Run Code Online (Sandbox Code Playgroud)
我想我不需要这两个文件。文件 1 是通过解析文件 2 的唯一用户名生成的。我的逻辑是获取我知道出现在文件 2 中的用户名列表,并循环遍历它,替换为sed
.
就像是:
for i in $(cat file1);do sed -e 's/$i/USER[X]';done
Run Code Online (Sandbox Code Playgroud)
当USER[X]
每个唯一的用户名递增。 …