我需要从文本文件中查找数字或重复字符,并且需要传递文件名作为参数。
示例:
test.txt数据包含
Zoom
Run Code Online (Sandbox Code Playgroud)
输出应该是这样的:
z 1
o 2
m 1
Run Code Online (Sandbox Code Playgroud)
我需要一个命令接受文件名作为参数,然后列出该文件中的字符数。在我的示例中,我有一个包含zoom单词的 test.txt。所以输出就像每个字母重复了多少次。
我的尝试:
vi测试.sh
#!/bin/bash
FILE="$1" --to pass filename as argument
sort file1.txt | uniq -c --to count the number of letters
Run Code Online (Sandbox Code Playgroud)
只是猜测?
cat test.txt |
tr '[:upper:]' '[:lower:]' |
fold -w 1 |
sort |
uniq -c |
awk '{print $2, $1}'
Run Code Online (Sandbox Code Playgroud)
m 1
o 2
z 1
Run Code Online (Sandbox Code Playgroud)