Joining all lines in a file using sed
Linux - - Posted on October, 12 at 10:19 pm
Sed (Stream EDitor) is a very powerful stream editor to manipulate text files.
I needed an utility that would join all lines in a text file to a single line with “\n” as a separator so that I could easily cut and paste inline velocity templates into java code. Here is the final sed command !
Explanation :
:a - is a label
/$/N - defines the scope of the match for the current and the (N)ext line
s/\n/\\n/; - replaces all EOL with “\n”
ta; - goto label a if the match is sucessful
Posted in Linux |




