我想在Linux上删除多行文本 [英] I want to remove multiple line of text on linux

查看:47
本文介绍了我想在Linux上删除多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就是这样.
之前:

Just like this.
Before:

1
19:22
abcde

2
19:23

3
19:24
abbff

4
19:25
abbc

之后:

1
19:22
abcde

3
19:24
abbff

4
19:25
abbc

我想删除没有字母的部分,如第2部分.
我认为我应该使用perl或sed.但是我不知道该怎么办.我尝试过这样.但这没用.

I want remove the section having no alphabet like section 2.
I think that I should use perl or sed. But I don't know how to do. I tried like this. But it didn't work.

sed 's/[0-9]\n[0-9]\n%s\n//'

推荐答案

sed用于单独行s/old/new/,仅此.对于其他任何事情,您都应该使用awk:

sed is for doing s/old/new/ on individual lines, that is all. For anything else you should be using awk:

$ awk -v RS= -v ORS='\n\n' '/[[:alpha:]]/' file
1
19:22
abcde

3
19:24
abbff

4
19:25
abbc

上面就是这样:

  • RS = 告诉awk输入记录用空白行分隔.
  • ORS ='\ n \ n'告诉awk输出记录也必须用空行分隔.
  • /[[[:alpha:]]/搜索并打印包含字母字符的记录.
  • RS= tells awk the input records are separated by blank lines.
  • ORS='\n\n' tells awk the output records must also be separated by blank lines.
  • /[[:alpha:]]/ searches for and prints records that contain alphabetic characters.

这篇关于我想在Linux上删除多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆