# -- 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
^^^^^ ^^^^
파일은 한 번만 지정하면 됩니다.