-2

I have n files, like:

file1:

Hannah
Lars

Test 123
1aaa
2eee 

file2:

Mike
Charly
Stephanie
Earl

Test 123
3ccc
4ddd
5eee

I want to remove all rows after "Test 123" from all n files. The number of rows to delete varies between files.

There's a very similar question How can I delete all lines before a specific string from a number of files in which sed -i.bak '1,/Test 123/d' file* works perfectly, but how can I do it for all lines after a specific string?

Thanks!

Dr-Bracket
  • 4,299
  • 3
  • 20
  • 28
  • 1
    See: [How to remove all lines after a line containing some string?](https://stackoverflow.com/q/65513225/3776858) – Cyrus Aug 07 '22 at 16:28

1 Answers1

0

Despite the comments and closed question, nothing in other threads worked. Figured out a solution:

for FILENAME in * ; do sed -i.bak '/Test 123/q' $FILENAME ; done
Dr-Bracket
  • 4,299
  • 3
  • 20
  • 28