linux - 如何使用 linux Find 命令查找和打印文档中的重复单词?
问题描述
我想知道变量名是否重复。所以,我想找到重复的单词。另外,是否可以输出重复的字线?
我在互联网上找到了它,但它不起作用。
# grep test.php | awk ‘{print $3}’ | sort | uniq -dc
例子。
$color2=$_POST['color2'] ?? '';
$color1=$_POST['color1'] ?? '';
$color3=$_POST['color3'] ?? '';
$color5=$_POST['color5'] ?? '';
$color6=$_POST['color6'] ?? '';
$color3=$_POST['color3'] ?? '';
$color8=$_POST['color8'] ?? '';
$color9=$_POST['color9'] ?? '';
$color13=$_POST['color13'] ?? '';
$color10=$_POST['color10'] ?? '';
$color11=$_POST['color11'] ?? '';
$color12=$_POST['color12'] ?? '';
$color13=$_POST['color13'] ?? '';
解决方案
使用以下代码创建脚本findDup.sh :
for n in $(seq 1 13)
do
no_of_lines=$(grep -n color$n= test.php|wc -l)
if [ $no_of_lines -gt 1 ]
then
grep -n color$n= test.php
echo "--------"
fi
done
当您在包含您的test.php的目录中运行它时,您将获得带有行号的重复行。
例子:
$ ./findDup.sh
3:$color3=$_POST['color3'] ?? '';
6:$color3=$_POST['color3'] ?? '';
--------
9:$color13=$_POST['color13'] ?? '';
13:$color13=$_POST['color13'] ?? '';
--------
您可以在上面的脚本中将限制从 13 更改为您想要的任何内容。
推荐阅读
- python - 从 2D 坐标生成 3D 曲面图
- c# - LeetCode:使用 HashSet 找到总和为 0 的 Triplet
- javascript - 如何安装 react-bootstrap v0.32.4?
- c# - 如何根据从 SQL Server 获取的 ID 设置 ComboBox 初始 DisplayMember 以显示正确的项目
- oracle - 为什么 Oracle 数据库跟踪文件中出现 TNS 错误
- pine-script - 止损超时
- android - 用联结表连接三个表
- python - 编写 CLI 时如何从子目录中导入类?
- scala - Flink的DataStream的timeWindow有问题[求助]
- ruby-on-rails - 如何在没有 Webpacker 的情况下将 Tailwind CSS 添加到 Rails?