把一个文本文档中只有一个数字的行给打印出来

时间:2021-02-27 13:00:32   收藏:0   阅读:0

 题目要求
用shell实现,把一个文本文档中只有一个数字的行给打印出来。

 参考答案

#!/bin/bash
while read line
do
    n=`echo $line |sed s/[^0-9]//g|wc -L`
    if [ $n -eq 1 ]
    then
    echo $line
    fi
done < 1.txt

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!