嗨我有这个短代码,我想用来计算重复行的数量,但我只希望显示数字
文件的输入
The Hunger Games:Suzanne Collins:1:1:1
The Hunger Games:test:1:1:1
期望的输出
found: 2
带有以下代码的输出
found: 2 The Hunger Games
使用的代码
echo "Title: "
read title
record=$(grep -io "$title" BookDB.txt | sort | uniq -c)
echo "found: " $record
答案 0 :(得分:1)
您可以使用awk
或cut
<强> awk中强>
echo "found: " $record | awk '{print $1 $2}'
<强>剪切强>
echo "found: 2 The Hunger Games" | cut -f1-2 -d" "
<强>测试强>
$ echo "found: " $record | awk '{print $1 $2}'
found: 2
$ echo "found: 2 The Hunger Games" | cut -f1-2 -d" "
found: 2