发布网友 发布时间:2022-04-23 02:11
共1个回答
热心网友 时间:2022-05-03 21:06
临下班随便写一个,大体我是这个思路,估计你看看明白,自己在改改就行了。
[flycat@redhat
~]$
cat
sfile.sh
#!/bin/bash
read
-p
"请输入要搜索的字串:"
STX
NES=(`ls
-l
|
grep
-v
'^d'
|
grep
-v
sfile.sh
|
awk
'{print
$9}'`)
for
i
in
${NES[*]}
do
#if
[
$i
-eq
2]
lines=`grep
"$STX"
$i
|
wc
-l`
NE=`grep
"$STX"
$i
-n`
TN=`grep
-o
"$STX"
$i
|
wc
-l`
echo
"匹配行数:$lines
字串个数:
$TN"
echo
-e
"显示所有内容:
$NE"
done
[flycat@redhat
~]$
./sfile.sh
请输入要搜索的字串:this
匹配行数:3
字串个数:
4
显示所有内容:
22:#
along
with
this
this
program;
see
the
file
COPYING.
If
not,
write
to
37:#
is
read
after
this
file.
114:#
Center
footer
is
the
list
of
files
on
this
sheet
if
landscape
[flycat@redhat
~]$