1

file.txt:

start some text works "HELLO" foo test
  sum
  other
end

start som "other" line with text 'also' thing foo end

and I want to delete the line in which "HELLO" is located and then delete all following lines until a line which has end written on it and nothing else!

I know this is a rather weird idea but I'm hoping either some basic bash command could do this or a function to which I pass the first string and the second and it deletes them and all in between!

The file should be looking like this at the end:


start som "other" line with text 'also'
  thing
  foo
end

THANK YOU!

NodeX4
  • 125

1 Answers1

1

Not bash, but sed:

$ sed '/"HELLO"/,/^end$/d' file.txt

start som "other" line with text 'also' thing foo end

or awk:

$ awk '/"HELLO"/,/^end$/{next} 1' file.txt

start som "other" line with text 'also' thing foo end

steeldriver
  • 136,215
  • 21
  • 243
  • 336