sed命令 - 适用于文件夹的所有文本文件(.txt) [英] sed command - apply in all text (.txt) files of folder

查看:733
本文介绍了sed命令 - 适用于文件夹的所有文本文件(.txt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想申请这个sed命令

I want to apply this sed command

sed '/begin 644/,$d' file1.txt > file1.txt

该目录下的所有文件..基本上我想保持具有相同的名称,但删除所有行某些字符串被发现后..我该怎么调整这个sed命令被应用到所有的文本(.txt )文件的文件夹,并保持原来的名称?

to all files of the directory.. basically I want to keep the having the same name but deleting all lines after a certain string is found.. how can i adjust this sed command to be applied to all the text (.txt) files in the folder and keep their original names ?

编辑:我使用的是Mac OS X,我不知道是否有某些问题sed命令...

EDIT : I am using Mac OS X I don't know if there is some issue with the sed command...

如果我试着做

sed -i '/begin 644/,$d' *.txt

我得到一个错误的sed:1:替换命令坏标志:'X'

i get an error sed: 1: bad flag in substitute command : 'x'

2日编辑:!阿努的回答作品

2nd EDIT : Anu's answer works !

推荐答案

您可以使用此找到 SED

find . -maxdepth 1 -name '*.txt' -exec sed -i.bak '/begin 644/,$d' {} + 

或者,如果你想保持开始644

find . -maxdepth 1 -name '*.txt' -exec sed -i.bak -n '1,/begin 644/p' {} + 

这篇关于sed命令 - 适用于文件夹的所有文本文件(.txt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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