用awk,一条命令就可以搞定:
1
awk '{print $0" "FNR}' file.txt >result.txt其中,$0表示当前处理的文件行内容,FNR表示当前处理的文件行
行号
。
结果存在result.txt中。
为拓展思路,下面用一个不同的方法:
用sed得到每行行号,存入一个tmp文件,然后用paste合并这两个行数相同的文件就得到了。
假设你的原始文件名称为file.txt。
#!/bin/sh
sed -n '=' file.txt >tmp
paste file.txt tmp >result.txtrm -f tmp1、echo “5 * * * * /root/crontab01” >>/tmp/root.crontab
2、sed -i '$a 5 * * * * /root/crontab01' /tmp/root.crontab
3、awk '{print $0} END{print “5 * * * * /root/crontab01”}' /tmp/root.crontab
1、通常用sed关闭SELINUXsed -i 's@SELINUX=enforcing@SELINUX=disabled@' /etc/sysconfig/selinux 将enforcing替换成disabled。
2、sed -i '10d' /etc/sysconfig/selinux删除 /etc/sysconfig/selinux第10行。
3、sed -i '11a hello world' /etc/sysconfig/selinux 在第11行后增加内容hello world。
4、sed -n '/ing/p' /etc/sysconfig/selinux 查询包含关键字ing所在所有行。欢迎分享,转载请注明来源:内存溢出