Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux命令检索唯一的单词,并与标点符号一起计数 tr-c'[:alnum:][\n*]检索标点符号_Linux_Bash_Shell - Fatal编程技术网

Linux命令检索唯一的单词,并与标点符号一起计数 tr-c'[:alnum:][\n*]检索标点符号

Linux命令检索唯一的单词,并与标点符号一起计数 tr-c'[:alnum:][\n*]检索标点符号,linux,bash,shell,Linux,Bash,Shell,下面的命令检索唯一的单词和计数。我想检索标点符号以及唯一的字数 实现这一点的方法是什么?您可以使用[:punct:][/code>检索标点符号 您可以运行: tr -c '[:alnum:]' '[\n*]' < 4300-0.txt | sort | uniq -c | sort -nr | head 输出将是: aaa, aaa 您可以使用tee拆分输入,并分别提取标点和alnum 1 aaa 1 aaa, 应输出: echo "Helo, world!" | { t

下面的命令检索唯一的单词和计数。我想检索标点符号以及唯一的字数


实现这一点的方法是什么?

您可以使用
[:punct:][/code>检索标点符号

您可以运行:

tr -c '[:alnum:]' '[\n*]' < 4300-0.txt | sort | uniq -c | sort -nr | head 
输出将是:

aaa,
aaa

您可以使用
tee
拆分输入,并分别提取标点和alnum

1 aaa
1 aaa,
应输出:

echo "Helo, world!" |
{ 
    tee >(tr -c '[:alnum:]' '\n' >&3) |
    tr -c '[:punct:]' '\n'
} 3>&1 |
sed '/^$/d' |
sort | uniq -c | sort -nr | head
echo "Helo, world!
OK!" |
sed '
    s/\([[:alnum:]]\+\)\([^[:alnum:]]\)/\1\n\2/g
    s/\([[:punct:]]\+\)\([^[:punct:]]\)/\1\n\2/g
    s/[^[:punct:][:alnum:]]/\n/g
' |
sed '/^$/d' |
sort | uniq -c | sort -nr | head
一个简短的
sed
脚本似乎也能起作用:

  1 world
  1 Helo
  1 !
  1 ,
应输出:

echo "Helo, world!" |
{ 
    tee >(tr -c '[:alnum:]' '\n' >&3) |
    tr -c '[:punct:]' '\n'
} 3>&1 |
sed '/^$/d' |
sort | uniq -c | sort -nr | head
echo "Helo, world!
OK!" |
sed '
    s/\([[:alnum:]]\+\)\([^[:alnum:]]\)/\1\n\2/g
    s/\([[:punct:]]\+\)\([^[:punct:]]\)/\1\n\2/g
    s/[^[:punct:][:alnum:]]/\n/g
' |
sed '/^$/d' |
sort | uniq -c | sort -nr | head