Reputation: 3275
I want to apply this sed command
sed '/begin 644/,$d' file1.txt > file1.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 ?
EDIT : I am using Mac OS X I don't know if there is some issue with the sed command...
if i try to do
sed -i '/begin 644/,$d' *.txt
i get an error sed: 1: bad flag in substitute command : 'x'
2nd EDIT : Anu's answer works !
Upvotes: 2
Views: 2811
Reputation: 785146
You can use this find
with sed
:
find . -maxdepth 1 -name '*.txt' -exec sed -i.bak '/begin 644/,$d' {} +
Or if you want to keep begin 644
:
find . -maxdepth 1 -name '*.txt' -exec sed -i.bak -n '1,/begin 644/p' {} +
Upvotes: 3
Reputation: 2236
You can use the edit in place sed option and the star selector like so
sed -i '/begin 644/,$d' *.txt
Upvotes: 1
Reputation: 8839
Just use in-place version of sed
as
sed -i '/begin 644/,$d' file1.txt
Upvotes: 2