-2
编写一个shell脚本来计算文件中的行数,字符数,字数(不使用命令)。同时从出现的文件中删除单词“Linux”的出现并将结果保存到新文件中。用于计数行数的shell脚本程序
编写一个shell脚本来计算文件中的行数,字符数,字数(不使用命令)。同时从出现的文件中删除单词“Linux”的出现并将结果保存到新文件中。用于计数行数的shell脚本程序
这是最接近我能得到不使用任何第三方软件包...
#!/bin/bash
count=0
while read -r line
do
count=$((count + 1))
done < "$filename"
echo "Number of lines: $count"
set
将该行分成$#
位置参数。${#line}
。${line//Linux}
。所有一起:
while read -r line
do
((++count))
set -- $line
((wordcount+=$#))
((charcount+=${#line}+1)) # +1 for the '\n'
echo "${line//Linux}"
done < "$filename" >anewfile
echo "Number of lines: $count"
echo "Number of words: $wordcount"
echo "Number of chars: $charcount"
http://ryanstutorials.net/bash-scripting-tutorial/ – MYGz