作者:我确实是一只猪_143_267 | 来源:互联网 | 2023-10-12 20:32
ImlearningUNIXforschoolandImsupposedtocreateacommandlinethattakesatextfileandge
I'm learning UNIX for school and I'm supposed to create a command line that takes a text file and generates a dictionary index showing the words (exluding articles and prepositions) and the lines where it appears in the file.
我正在学习UNIX for school,我应该创建一个命令行,它接受一个文本文件并生成一个字典索引,显示单词(包括文章和介词)以及它在文件中出现的行。
I found a similar problem as mine in: https://unix.stackexchange.com/questions/169159/how-do-i-use-awk-to-create-an-index-of-words-in-file?newreg=a75eebee28fb4a3eadeef5a53c74b9a8 The problem is that when I run the solution
我发现了类似的问题:https://unix.stackexchange.com/questions/169159/how-do-i-use-awk-to-create-an-index-of-words-in-file?newreg = a75eebee28fb4a3eadeef5a53c74b9a8问题是当我运行解决方案时
$ awk '
{
gsub(/[^[:alpha:] ]/,"");
for(i=1;i<=NF;i++) {
a[$i] = a[$i] ? a[$i]", "FNR : FNR;
}
}
END {
for (i in a) {
print i": "a[i];
}
}' file | sort
The output contains special characters (which I don't want) like:
输出包含特殊字符(我不想要),如:
-Quiero: 21
Sancho,: 2, 4, 8
How can I remove all the special characters and excluding articles and prepositions?
如何删除所有特殊字符并排除文章和介词?
1 个解决方案