从多个文件中删除文本 [英] Delete text from multiple files

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

问题描述

我想从多个文件中删除文本。它可能是从10到1000个文件,所以手工删除是太多的工作。
我发现了几个SO问题,例如:
删除多个文本文件中的特定行与免费软件应用程序?但没有一个帮助

要找到和替换,我可以写一个Perl命令,但它没有选择。
例如,我想删除所有文件中的前四行。
有谁知道一个解决方案?或者也许是一个应用我更喜欢没有VBScript的东西。

解决方案

sed(1) AWK(1) 对于这份工作来说非常棒。例如,要删除当前目录中所有 .txt 文件的前四行:

  sed -i〜1,4d * .txt 

这会删除所有 .txt 文件的前4行显示在当前目录的子目录中:

  find。 -type〜''''} + 


I want to delete text from multiple files. It could be from 10 to 1000 files, so deleting it by hand is too much work. I found a couple of SO questions, such as: Delete specific lines in multiple Text Files with freeware App? but none of them helped

To do find and replace, I could write a perl command, but it lacks options. For example, I want to delete the first four lines in all files. Does anyone know a solution? Or maybe an app? I would prefer something without VBScript.

解决方案

sed(1) or awk(1) would be great for this job. For example, to delete the first 4 lines of all of the .txt files in the current directory:

sed -i~ 1,4d *.txt

This will delete the first 4 lines of all .txt files anywhere in a subdirectory of the current directory:

find . -type f -iname \*.txt -exec sed -i~ 1,4d '{}' +

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

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