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

$cata1

2

3

4

5

6

7

8

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

$sed '1,4d'a5

6

7

8

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

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

4

5

6

7

8

一个例子:

我有一个list文件如下:

$cat list

unknown_other_2 #文件名,我要从文件里抓取一些信息,下同,发现下图里没有有些没有我想要的信息,test后面的数字代表这个list文件的行号

unknown_other_5   #我要删除大小为0的行

unknown_other_1

F002_other_1

unknown_other_14

t_unknown_other_4

t_unknown_other_6

t_unknown_other_4

t_unknown_other_1

t_unknown_other_4

t_unknown_other_12

t_unknown_other_4

t_unknown_other_13

t_unknown_other_10

t_unknown_other_12

t_unknown_other_4

t_unknown_other_42

t_unknown_other_16

t_unknown_other_27

t_unknown_other_14

t_unknown_other_31

t_unknown_other_12

t_unknown_other_10

t_unknown_other_13

t_unknown_other_11

t_unknown_other_22

t_unknown_other_21

t_unknown_other_45

t_unknown_other_42

t_unknown_other_4

t_unknown_other_33

t_unknown_other_1

t_unknown_other_12

t_unknown_other_14

t_unknown_other_1

t_unknown_other_31

t_unknown_other_4

t_unknown_other_11

t_unknown_other_11

t_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 执行

sed 删除某一行_sed删除指定行相关推荐

  1. sed 删除某一行_sed 删除最后几行 和删除指定行

    sed 想删除文件中的指定行,是可以用行号指定也可以用RE来匹配的. 删除指定的行[可以指定行号删除.匹配字符串来删除][root@Jason64-17 ~]# cat -n seq.txt 1 ok ...

  2. sed 删除某一行_sed 删除最后几行 和删除指定行 awk使用

    sed 想删除文件中的指定行,是可以用行号指定也可以用RE来匹配的. 删除指定的行[可以指定行号删除.匹配字符串来删除] [root@Jason64-17 ~]# cat -n seq.txt 1 o ...

  3. 【linux】使用sed删除大文件中的指定行

    [linux]使用sed删除大文件中的指定行 引言: 最近在清洗数据时遇到一个超大的文件,需要删除其中不符合数据要求的指定行.使用之前写好的python脚本清洗速度太慢,于是检索了许多linux文件处 ...

  4. sed 删除某一行_sed 命令删除指定行

    record 文件里有以下数据1607583364561;/app/rm/a.x;./a.x;1210145604 1607583364561;/app/rm/b.x;./b.x;1210145604 ...

  5. shell删除最后一行、删除第一行、比较文件

    删除文件第一行: sed -i '1d' filename 删除文件最后一行: sed -i '$d' fileName 比较文件的方法: 1)comm -3 --nocheck-order file ...

  6. python怎样删除某一行_python删除某一行

    整理了网络上的一些方法,一般有两种方法: 第一种:是先把文件读入内存,在内存中修改后再写入源文件. 例子:将内容包含"123"的所有行删去: with open('C:/Users ...

  7. python中删除某一行_python 删除大文件中的某一行(最有效率的方法)

    用 python 处理一个文本时,想要删除其中中某一行,常规的思路是先把文件读入内存,在内存中修改后再写入源文件. 但如果要处理一个很大的文本,比如GB级别的文本时,这种方法不仅需要占用很大内存,而且 ...

  8. python删除第一行_Python删除文件第一行

    一.代码实例: def del_firstline(): for line in fileinput.input("file.txt", inplace = 1): if not ...

  9. sed删除指定行的上一行

    有这么一个需求,需要从若干个apache虚机配置文件中删除一段内容,类似下面这种 <VirtualHost *> ServerName abc.com DocumentRoot /home ...

最新文章

  1. 关闭/开启 ubuntu 自动更新提示
  2. python读取视频分辨率_Python实现以不同分辨率分类视频
  3. 用计算机计算的手抄报内容,关于数学计算手抄报
  4. 有哪些大数据处理工具?
  5. C#多线程之旅(4)——APM初探
  6. 【年度回忆录】如何做到1年90000粉丝?
  7. Android 系统(188)---Android开发:ListView、AdapterView、RecyclerView全面解析
  8. 全选、取消全选、单选
  9. Photoshop中预设资源安装方式-笔刷、动作、渐变、形状、样式等
  10. 深入理解GBDT回归算法
  11. 迷失逃脱小程序_恐怖游戏大全:奇幻夜之迷失!密室逃脱解谜恐怖小程序
  12. HC Bridge容器网络模式分享
  13. 恭贺除夕,没什么才艺展示,就给大家画新年四格小漫画吧 >⌒<
  14. 猿人学web端爬虫攻防大赛赛题解析_第四题:雪碧图、样式干扰
  15. ibm x服务器硬盘检测,IBM System x 服务器自带RAID1的故障恢复
  16. 委托实现信用卡用户定时还款功能
  17. [转载] 苹果 AppStore 应用商店生存之道
  18. 抓取国家统计局2018年的省市区街道数据
  19. 【深度学习】【积分梯度】深度网络的公理归因(Axiomatic Attribution for Deep Networks)
  20. 给女朋友表白节日送给女朋友的网页(精美)

热门文章

  1. 登录页面(动态背景)
  2. CyclicBarrier---JDK1.8源码分析
  3. MFC控件绘制透明png图片或者半透明图片
  4. 如何把D盘多余空间返还给C盘
  5. Windows10系统goland代码跳转ctrl + alt +←或→箭头快捷键无效
  6. 宜家订单JSON_怎么评价宜家(IKEA)?
  7. 年薪30万只是中游水平,算法工程师是一种怎样的存在?
  8. 什么样的自学Java网站才适合学习者?
  9. oneshot一次性服务
  10. 批量修改Excel中的图片大小方法