假设我有下一个文件:
1 Blue
2 Red
3 Yellow
4 Yellow
5 Yellow
6 Purple
7 Purple
8 Green
我想得到以下文件,用" NA"
替换重复的变量1 Blue
2 Red
3 Yellow
4 NA
5 NA
6 Purple
7 NA
8 Green
答案 0 :(得分:5)
试试这个 -
$ awk 'a[$2]++{$2="NA"} 1' f
1 Blue
2 Red
3 Yellow
4 NA
5 NA
6 Purple
7 NA
8 Green
答案 1 :(得分:1)
$ awk '{print $1, ($2==p ? "NA" : $2); p=$2}' file
1 Blue
2 Red
3 Yellow
4 NA
5 NA
6 Purple
7 NA
8 Green
答案 2 :(得分:0)
def del_user_from_lists(user):
user.user_lists.through.objects.filter(user_id=user.pk).delete()