我有一个多行多内容的文件。某些行以特定的模式开始,这种情况可能会再次发生。例如。
some line
some line
this: idA001 text
this: idA002 text
some line
this: idB001 text
this: idA001 text
this: idA002 text
this: idC001 text
...
我想数数this: id*的每一次首次发生。
如果我使用cat file | grep "this: " | wc -l,我会统计每一个事件..。我是否需要编写一个脚本,先对行进行筛选,然后消除重复,还是在一个一行ba
我必须找出一个文件中使用shell这个词的次数。我使用grep "shell" test.txt | wc -w来统计这个单词被使用了多少次,但是结果是4次而不是3次。
this is a test file
for shell_A
shell_B
sh
shel
and
shell_C
script project
在unix或linux中,如何根据sed、grep或awk在unix上获取目录中文件的名称?
我想我可以这样做:
for i in $(ls /tmp/files/date*); do
if [ $(cat $i | head -n 1 | grep -c "6") >= 1 ] ; then
echo $i
fi
done
我需要它来搜索某个目录中的所有文件(每个文件只有第一行),然后返回其中包含字符串的文件。
谢谢,蒂姆