比如需要查看passwd文件9-12行的文件可以用:
[root@localhost dbdata_qeesoo]# cat -n /etc/passwd |awk 'NR >= 9'|awk 'NR <= 4'
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 news:x:9:13:news:/etc/news:
11 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
12 operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost dbdata_qeesoo]# nl /etc/passwd |awk 'NR >= 9'|awk 'NR <= 4'
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 news:x:9:13:news:/etc/news:
11 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
12 operator:x:11:0:operator:/root:/sbin/nologin
[root@localhost dbdata_qeesoo]#
[root@server ~]# cat check_line.sh
read -p "Please enter the file path & name which you want to check
: " filename
if [ "$filename" == "" ]; then
exit
fi
test ! -e $filename && echo "The filename $filename DO NOT
exist" && exit
read -p "start from which line ?? " start_line
read -p "end of which line ?? " stop_line
if [ "$start_line" -gt "$stop_line" ]; then
echo "Start line nerver geart then stop line, program end!!
please check"
exit
fi
end_line=`echo "( $stop_line - $start_line ) + 1"
|bc`
cat $filename |awk 'NR >= '$start_line''|awk 'NR <= '$end_line''
[root@server ~]#
阅读(1381) | 评论(0) | 转发(0) |