你这个不难实现,问题你是你表达不清楚,一会说"d1“关键字,一会又说"1|"
前面你说。如果输入查询内容"d1",输出“3”行,什么依据?因为3行有"d"?
我猜你是这个意思吧?
cat a.txt | grep "|." -o | tr -d "|" | uniq -c
[root@localhost shell]# cat a.txt | grep d | wc -l
3
[root@localhost shell]# cat a.txt | grep b | wc -l
2
[root@localhost shell]# cat a.txt | grep e | wc -l
2
[root@localhost shell]# cat a.txt | grep c | wc -l
5