删除文件中的行 [英] Deleting lines in a file

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

问题描述

我在一个目录中有很多文件,我需要在其中进行常见的替换。


我需要删除两个匹配模式之间的所有行



我需要匹配一个有单词的行 chkstats捕获从这一行开始


(假设它出现在第40行)到另一行未能提取统计数据 (可能会在
line no 100中出现)并且在下一行有紧密的支撑(''}),也需要将其移除。



简而言之,必须在文件中删除40到100之间的所有行。(包括符号})


我试过了同样我可以匹配文件中的模式,但我不知道如何删除线条..匹配模式之间..任何人都告诉我如何做同样的事情。


I have many files in a dirctory in which I need to make the common subsitution.

I need to delete all lines between two matched patterns


I need to match a line having words " chkstats to capture " starting from this line

(Say it occurs at line 40) to another line "Failure to pull stats" (which may come in

line no 100) and there is close brace(''}") at the next line which also needs to be removed.


In short all lines from 40 to 100 must be deleted in the file.(Including the symbol "}")

I tried the same I can match the pattern in the file but I dont know how to remove the lines..between the matched patterns..Can anyone tell me how to do the same.


展开 | 选择 | Wrap | 行号

推荐答案

发布什么t他的实际数据看起来像是要删除行。
post what the real data looks like you are wanting to delete the lines from.


以下内容应该有效。至少你可以使用逻辑作为模型。

Something like the following should work. At the very least you can use the logic as a model.

展开 | 选择 | Wrap | 行号


使用perls的不同方法编辑:

A different approach using perls inplace editor:

展开 | 选择 | Wrap | 行号


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

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