I'm trying to convert file wich could have one or more lines and extract word "three". Sample file is oneliner:
[test@test tmp]$ cat test1
onetwothreefourfive[pi@pidora tmp]$
I could make it in this way:
[test@test tmp]$ sed -e 's/.*two\(.*\)four.*/\1/' test1
three[pi@pidora tmp]$
But I have to make sure that my file is oneliner, so I'm using command from this question: How can I replace a newline (\n) using sed?
[test@test tmp]$ sed -e ':a;N;$!ba;s/\n/ /g' -e 's/.*two\(.*\)four.*/\1/' test1
onetwothreefourfive[pi@pidora tmp]$
It doesn't work.
[test@test tmp]$ sed -e ':a;N;$!ba;s/\n/ /g' test1| sed -e 's/.*two\(.*\)four.*/\1/'
three[test@test tmp]$
I use pipe and it works. Please explain to me why sed works wrong without pipe.
Thanks!