С помощью awk
;
$ awk 'NR==FNR{ seen[$0]++;next }
{ print $0 (($0 in seen)?" TRUE":" FALSE")}' userbanned.list alluser.list
user1 FALSE
user4 TRUE
user2 TRUE
user4 TRUE
user5 TRUE
user3 FALSE
user2 TRUE
awk
сломать -вниз:
NR==FNR - Execute next block for 1st file only "userbanned.list" seen[$0]++ - Create an associative array with the key as '$0' (whole line) of file "userbanned.list" next - continue read next line of file "userbanned.list" print $0 - Print the whole line of "alluser.list" file,, now FNR reset to 1 since next file read by awk, but NR is still incrementing until the last line from last file read. (($0 in seen)?" TRUE":" FALSE") - This known as Ternary operator '(condition)?"If-True":"If-False"'. It's short form of if/else/ and checks if current line in file "alluser.list" exists in array then print "TRUE" else "FALSE".
Я также вижу, что у вас есть дублированные пользователи, которые будут печатать дважды или более, вы можете уникализовать строки в обоих файлах, а затем передать их в awk
, как показано ниже:
$ awk 'NR==FNR{ seen[$0]++;next } { print $0 (($0 in seen)?" TRUE":" FALSE")}
' <(sort -u userbanned.list) <(sort -u alluser.list)
user1 FALSE
user2 TRUE
user3 FALSE
user4 TRUE
user5 TRUE