0
#!/bin/sh
#需求:
#判断所给目录内哪些二级子目录下没有text.txt。有text.txt文件的子目录根据文件计算选项中单词数最大的值(选项间以|分隔,单词数以空格分隔)
#2016年9月1日 & 李宏伟
#version 1
cd /tmp/0101
for i in `ls`
do
if
[ -f ${i}/test.txt ]
then
n=`cat ${i}/test.txt |wc -w` && echo "$n $i |" >> /tmp/tongji.txt
fi
done
cat /tmp/tongji.txt |xargs
echo "please hold on latter" && sleep 3
sort -k1 -rn /tmp/tongji.txt |xargs
echo > /tmp/tongji.txt
#需求:
#判断所给目录内哪些二级子目录下没有text.txt。有text.txt文件的子目录根据文件计算选项中单词数最大的值(选项间以|分隔,单词数以空格分隔)
#2016年9月1日 & 李宏伟
#version 1
cd /tmp/0101
for i in `ls`
do
if
[ -f ${i}/test.txt ]
then
n=`cat ${i}/test.txt |wc -w` && echo "$n $i |" >> /tmp/tongji.txt
fi
done
cat /tmp/tongji.txt |xargs
echo "please hold on latter" && sleep 3
sort -k1 -rn /tmp/tongji.txt |xargs
echo > /tmp/tongji.txt
0
a=`find /tmp -maxdepth 3 -type f -name 'word.txt'`
if [ -z "$a" ]
then
echo "file word.txt is not under /tmp"
exit
else
for i in `cat $a`
do
b=`echo $i |wc -m`
let c=b-1
echo $b $i >>/tmp/count.txt
done
fi
cat /tmp/count.txt |sort -rn |head -n1 |awk '{print $2}'
没看懂题目的需求,我私自改了下需求,查找/tmp下的二级子目录有无word.txt文件,没有则显示没有,如果有word.txt,统计出文件里字母最多的一个单词
留作存档,我忘了当时怎么写的
#!/bin/bash
a=`find /tmp -maxdepth 3 -type f -name 'word.txt'`
if [ -z "$a" ]
then
echo "file word.txt is not under /tmp"
exit
else
for i in `cat $a`
do
b=`echo $i |wc -m`
let c=b-1
echo $b $i >>/tmp/count.txt
done
fi
cat /tmp/count.txt |sort -rn |head -n1 |awk '{print $2}'
0
#!/bin/bash
#Auth: Citizen Wang
#Scripts: Search file test
read -p "Please type whole path of directory: " d
for i in `find $d -mindepth 1 -maxdepth 2 -type f -name test`
do
if [ -n "$i" ];then
echo $i
echo '' > /tmp/count.txt
for m in `cat $i`
do
b=`echo $m |wc -m`
echo $b $m >> /tmp/count.txt
done
fi
cat /tmp/count.txt | sort -nr |head -n1 | awk '{print $2}'
done
编辑回复