Chinaunix首页 | 论坛 | 博客
  • 博客访问: 636449
  • 博文数量: 137
  • 博客积分: 6189
  • 博客等级: 准将
  • 技术积分: 1559
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-15 16:39
文章分类

全部博文(137)

文章存档

2010年(3)

2009年(1)

2008年(49)

2007年(56)

2006年(28)

分类: LINUX

2008-04-30 12:00:07

比如需要查看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 ~]#
阅读(1338) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~