There are many linux tools available to do search and replace, with sed being one of the most commonly used. However, tools like sed work line-by-line. If you need to replace/remove newline characters then things get complicated. It can be done with sed, but it’s not pretty.

The nicest solution I’ve seen is using awk. awk uses a Record Separator (RS) setting to determine how to split each record, and an Output Record Separator (ORS) setting to determine how to split the records as they are output. By default, RS and ORS are both set to '\n' (newline), meaning it reads in text line-by-line and outputs them in the same form. By changing ORS to something else, we can get all of the data printed on one line.

The examples below will use a file named random_data.txt which contains the following data:

18838ef123e
f33a244eb1e
4492b3091o9
9o7ef44b22e
77a1194g229

To replace the newline characters with a space, we can use the following:

awk '{ print $0; }' RS='\n' ORS=' ' < random_data.txt 18838ef123e f33a244eb1e 4492b3091o9 9o7ef44b22e 77a1194g229

ORS does not have to be one character:

awk '{ print $0; }' RS='\n' ORS=' :: ' < random_data.txt 18838ef123e :: f33a244eb1e :: 4492b3091o9 :: 9o7ef44b22e :: 77a1194g229 ::

The above commands are overly verbose, making it more obvious as to what's going on. However, both the RS value and the print $0 are default settings. RS can be omitted completely, and the print code can be replaced with the number 1. This 1 is a true condition, indicating to awk to use the default behaviour.

So to repeat the example of replacing newlines with a space, we can shorten the command to:
awk 1 ORS=' ' < random_data.txt 18838ef123e f33a244eb1e 4492b3091o9 9o7ef44b22e 77a1194g229

The shorter command is a bit more abstract but does the same job while cutting the command line length in half.