sed command - apply in all text (.txt) files of folder

后端 未结 3 1381
一生所求
一生所求 2021-01-22 00:34

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 h

相关标签:
3条回答
  • 2021-01-22 01:00

    You can use the edit in place sed option and the star selector like so

    sed -i '/begin 644/,$d' *.txt
    
    0 讨论(0)
  • 2021-01-22 01:01

    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' {} + 
    
    0 讨论(0)
  • 2021-01-22 01:08

    Just use in-place version of sed as

    sed -i '/begin 644/,$d' file1.txt
    
    0 讨论(0)
提交回复
热议问题