Используя awk для него. Тестовые файлы:
$ cat a.txt
one
two
three
four
four
$ cat b.txt
three
two
one
awk:
$ awk '
NR==FNR { # process b.txt or the first file
seen[[111]] # hash words to hash seen
next # next word in b.txt
} # process a.txt or all files after the first
!([111] in seen)' b.txt a.txt # if word is not hashed to seen, output it
Дубликаты производятся:
four
four
Для предотвращения дубликатов добавьте каждое недавно встреченное слово в a.txt к seen
хеш:
$ awk '
NR==FNR {
seen[[113]]
next
}
!([113] in seen) { # if word is not hashed to seen
seen[[113]] # hash unseen a.txt words to seen to avoid duplicates
print # and output it
}' b.txt a.txt
Вывод:
four
, Если списки слов разделяются от запятой, как:
$ cat a.txt
four,four,three,three,two,one
five,six
$ cat b.txt
one,two,three
необходимо сделать несколько дополнительных полировок (for
циклы):
awk -F, ' # comma-separated input
NR==FNR {
for(i=1;i<=NF;i++) # loop all comma-separated fields
seen[$i]
next
}
{
for(i=1;i<=NF;i++)
if(!($i in seen)) {
seen[$i] # this time we buffer output (below):
buffer=buffer (buffer==""?"":",") $i
}
if(buffer!="") { # output unempty buffers after each record in a.txt
print buffer
buffer=""
}
}' b.txt a.txt
Вывод на этот раз:
four
five,six
Используйте метод removeAttr
.
$('selector').removeAttr('id')