精选30+云产品,助力企业轻松上云!>>>
新建一个文件并让文件中显示行号方便后续执行查看结果
cat -b /etc/passwd > a.txt
cat /a.txt
………………….省略N行
34 dhcpd:x:177:177:DHCP server:/:/sbin/nologin
35 lisi:x:500:500::/home/lisi:/bin/bash
36 zhangsan:x:501:501::/home/zhangsan:/bin/bash
37 mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
38 named:x:25:25:Named:/var/named:/sbin/nologin
39 qemu:x:107:107:qemu user:/:/sbin/nologin
40 radvd:x:75:75:radvd user:/:/sbin/nologin
编写脚本
[root@svr5 桌面]# vim /shell/del.sh
#!/bin/bash
lines=`cat $1 | wc -l`
sline=`expr $lines – 1`
sed -i \’\’$sline\’,+1d\’ $1
执行脚本
[root@svr5 桌面]# sh /shell/del.sh /a.txt
查看执行结果
[root@svr5 桌面]# cat /a.txt
…………………省略N行
35 lisi:x:500:500::/home/lisi:/bin/bash
36 zhangsan:x:501:501::/home/zhangsan:/bin/bash
37 mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
38 named:x:25:25:Named:/var/named:/sbin/nologin
ff8