Using shell
If shell solutions are allowable, then try:
$ echo $(cat inputfile)
Google Facebook yahoo cisco juniper oracle firetide attack
The above should work with any POSIX shell. With bash
:
$ echo $(<inputfile)
Google Facebook yahoo cisco juniper oracle firetide attack
Using sed
If we really must use awk
or sed
, then here is a sed
solution:
$ sed ':a;N;$!ba; s/\n/ /g' inputfile
Google Facebook yahoo cisco juniper oracle firetide attack
The above reads the whole file in (:a;N;$!ba
) and then replaces all newlines with spaces (s/\n/ /g
).
If the input file might contain extra spaces at the beginning for end of a line, we can remove them:
$ sed ':a;N;$!ba; s/[[:space:]]*\n[[:space:]]*/ /g' inputfile
Google Facebook yahoo cisco juniper oracle firetide attack