Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

replace a newline using sed linux bash

#All alternatives, unlike sed will not need to reach the last line to begin the process

#with bash, slow
while read line; do printf "%s" "$line "; done < file

#with perl, sed-like speed
perl -p -e 's/
/ /' file

#with tr, faster than sed, can replace by one character only
tr '
' ' ' < file

#with paste, tr-like speed, can replace by one character only
paste -s -d ' ' file

#with awk, tr-like speed
awk 1 ORS=' ' file

#Other alternative like "echo $(< file)" is slow, works only on small files and needs to process the whole file to begin the process.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #replace #newline #sed #linux #bash
ADD COMMENT
Topic
Name
3+3 =