Melanie Shebel
Melanie Shebel

Reputation: 2914

Bash: replace specific newline with space

I have numerous files with extension .awesome containing lines like the following:

something =
[51,42,12]

Where something =* is in all the files as well as **[ (numbers vary.)

I would like to get rid of the newline, but don't know how. I came across tr, but worry it would replace all newlines. My files contain multiple newlines that I would like to retain (only change this newline.) I've been able to successfully to find and replace in the past with sed, but am having specifically with the special characters (\n and =.) In addition, I'm reading that sed is line by line and cannot handle something like this.

Any guidance would be appreciated.

Upvotes: 2

Views: 222

Answers (1)

RomanPerekhrest
RomanPerekhrest

Reputation: 92854

GNU sed solution:

Sample test.awesome file contents:

some text
another text
something =
[51,42,12]

text
text

The job:

sed '/something =/{N; s/\n/ /;}' test.awesome

The output:

some text
another text
something = [51,42,12]

text
text

Upvotes: 2

Related Questions