我认为cat 命令不会单独完成这项工作。我想你应该看看 gnu core utils 包,你会发现很多工具:http://www.gnu.org/software/coreutils/manual/html_node/index.html
一种简单的方法是:
cat polls.csv |sed -s "s/.*,//"
sed -s "s/.*,//" 将最后一个逗号之前的所有内容替换为空,从而离开投票组织。
对于第二个问题,您可以继续使用sort -u,它将对所有内容进行唯一排序,然后使用wc -l 进行计数,例如:
cat polls.csv|sed -s "s/.*,//"|sort -u|wc -l
对于辅音检查,它是一个单独的问题定义。有很多方法可以检查它。这是我头顶上的方法:
# /bin/python
import sys
import re
consonants = "bcdfghjklmnpqrstvwxyz"
def count_consonants(word):
count = 0
for x in word:
if x in consonants:
count += 1
return count
while True:
line = sys.stdin.readline()
if line:
line = line.rstrip()
line = re.sub(" +", " ", line)
words = line.split(" ")
for w in words:
c = count_consonants(w)
if c >= 6:
print w
else:
break
请将其保存为script.py 然后执行:
cat polls.csv|sed -s "s/.*,//"|sort -u|python script.py
或
cat words|python script.py