regex - Remove \n newline if string contains keyword -


I would like to know if I can delete a \ n (Newline) current There are more ore keywords than one list in the row; For example, if I want to remove \ n if it contains halo or world in it.

Example:

  This is an original file with rows of words like hello and world, this is the end of the file  

And the result will be:

  This is an original file containing lines with words like hello and world, this is the end of the file  

I want to use sed, or awk, and if necessary, grep, wc or whatever works for this purpose I will be able to do so on many files I want to be

Here SAD is easy to use

  sed -r ': A; $! {N; B)}}} (/ hello | world) [^ \ n] *) \ n / 1 / g 'file  

explanation

  • : A; $! {N; Left} Read the full file in the pattern, like: it \ \ \ \ \ and the world \ n has an original \ n file with lines with words like \ nthis file has an end $
  • Search on code> world
    and remove the next \ n ,
  • substitute the g command for regexp all the matches in the sed option Standing to apply, not only the first.

Comments