This is a text processing question. I have 2 files:
joeblogs
johnsmith
chriscomp
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
File 1 contains a list of unique usernames that appear in a log (file 2).
Desired output
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
I guess I don't need both files. File 1 is generated by parsing file 2 for the unique usernames. My logic was to get a list of usernames that I know appear in file 2, and loop through it, replacing with sed
.
Something like:
for i in $(cat file1);do sed -e 's/$i/USER[X]';done
Where USER[X]
increments with each unique username.
However I can't do this. I don't even think that logic is sound. Can I have help to achieve the desired output? awk
/sed
/grep
/bash
are all welcome.