# -- Q2 --
# Write a pipeline that finds the number of words in the book that have been used only once.
# Your pipeline should be case insensitive
echo "-- Q2 --"
onlyOnce=$(cat *txt | tr '[:upper:]' '[:lower:]' | tr -s '[:punct:][:space:]' ' '| tr ' ' '\n' | sort | uniq -ic | awk '$1 == 1 {print $2}')
echo "Words used only once:"
echo "$onlyOnce"
答案1
和awk
:
cat *txt |
tr '[:upper:]' '[:lower:]' |
tr -s '[:punct:][:space:]' |
awk '{a[$1]++}END{for (i in a) if (a[i] == 1) {print i}}'
在你的例子中,你不能这样做
cat files | ... | awk '{}' file
^^^^^ ^^^^
您只需指定文件一次。