博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sed删除指定行
阅读量:6982 次
发布时间:2019-06-27

本文共 1526 字,大约阅读时间需要 5 分钟。

待处理文本如1-8行文本

$cat a 12345678

sed删除连续指定行:如1-4行

$sed '1,4d' a5678

sed删除不连续指定行:如第一行和第三行

$sed -e '1d' -e '3d' a245678

 一个例子:

我有一个list文件如下:

$cat list unknown_other_2     #文件名,我要从文件里抓取一些信息,下同,发现下图里没有有些没有我想要的信息,test后面的数字代表这个list文件的行号unknown_other_5   #我要删除大小为0的行unknown_other_1      F002_other_1unknown_other_14t_unknown_other_4t_unknown_other_6t_unknown_other_4t_unknown_other_1t_unknown_other_4t_unknown_other_12t_unknown_other_4t_unknown_other_13t_unknown_other_10t_unknown_other_12t_unknown_other_4t_unknown_other_42t_unknown_other_16t_unknown_other_27t_unknown_other_14t_unknown_other_31t_unknown_other_12t_unknown_other_10t_unknown_other_13t_unknown_other_11t_unknown_other_22t_unknown_other_21t_unknown_other_45t_unknown_other_42t_unknown_other_4t_unknown_other_33t_unknown_other_1t_unknown_other_12t_unknown_other_14t_unknown_other_1t_unknown_other_31t_unknown_other_4t_unknown_other_11t_unknown_other_11t_unknown_other_3

test文件,test后面的数字对应上面list行号:

代码如下:

ls -l |awk '{if ($5==0){print $9}}'|cut -d "t" -f3|xargs   -I {} echo -e "-e {}d"|xargs|xargs -I {} echo sed -i -e {} list|sh#执行结果#sed -i -e test10d -e test12d -e test14d -e test16d -e test2d -e test27d -e test3d -e test31d -e test32d -e test33d -e test35d -e test38d -e test39d -e test4d -e test40d -e test5d -e test9d list#分解说明#ls -l |awk '{if ($5==0){print $9}}'  列出大小为0的test文件#cut -d "t" -f3  抓取后面的数字    用字符"t" 分割test文件,取第三列数字部分#xargs -I {} echo -e "-e {}d"|xargs|xargs -I {} echo sed -i -e {} list  打印执行语句#sh  执行

 

转载于:https://www.cnblogs.com/xlij1205/p/10490751.html

你可能感兴趣的文章
docker logstash 使用
查看>>
Linux Study之--RedHat EL6配置VNC server
查看>>
负载均衡集群之lvs
查看>>
(三) Graphivz 基本图片类型
查看>>
ubuntu 升级过程中断电时遇到的问题总汇
查看>>
Netscaler基于policy的log action
查看>>
删除sql server 表中的重复数据!
查看>>
水仙花数
查看>>
初识set集合
查看>>
怎么寻回调整分区后盘符丢失的数据
查看>>
警惕!MySQL成数据勒索新目标
查看>>
linux系统学习第一天
查看>>
eclipse的安卓开发插件『ADT』在线安装不成功的解决方案
查看>>
第12章,网络管理(下)网络基础配置
查看>>
DTU是什么 DTU种类及应用领域分析
查看>>
基于Zynq-7000高速数据采集解决方案
查看>>
【VMware vSAN 6.6】5.2.运行状况:我们有软硬件项目解决方案
查看>>
细数iOS上的那些安全防护
查看>>
tar命令常用参数解释
查看>>
SourceTree跳过Atlassian账号,免登陆,跳过初始设置
查看>>