Solved sed script not working

balanga

Son of Beastie

Reaction score: 118
Messages: 2,892

I was looking for a sed script to concatenate mutiple lines into one and came across this post which provided this script
Bash:
sed -e :a -e N -e 's/\n/ /' -e ta yourfile.txt >newfile.txt
with the following explanation
:a # label 'a' to jump back to later on
N # Append next line to sed's buffer
s/\n/ / # replace exactly one newline (\n) with a space
ta # if the last replace command was succesfull, jump to label 'a'.
# (if this does not happen, the entire file was read: end
I tried this, but it doesn't work. Is it only for GNU sed?
 

jpierri

Member

Reaction score: 22
Messages: 56

On GNU sed it works right as it is, or as this:

sed -e ':a N; s/\n/ /; ta' yourfile.txt >newfile.txt

Unfortunatelly it doesn't works on our sed :(

Can't you replace those newlines using something like this?
cat yourfile.txt | tr '\n' ' ' >newfile.txt
 
Top