Currently, i have to manually stream the edited content into a new file and then rename the new file to the original file name I'm debugging a shell script and trying to find out the task performed by the following command Sed with special characters asked 14 years, 6 months ago modified 2 years, 11 months ago viewed 90k times The following command is correctly changing the contents of 2 files Use this solution with gnu sed Sed ':a;n;$!ba;s/\n/ /g' file this will read the whole file in a loop (':a;n;$!ba), then replaces the newline (s) with a space (s/\n/ /g)
Additional substitutions can be simply appended if needed Sed starts by reading the first line excluding the newline into the pattern space Create a label via :a Append a newline and next line to the pattern. I run this command to find and replace all occurrences of 'apple' with 'orange' in all files in root of my site But it doesn't go through sub directo.
First, understanding the sed expression at hand S/pattern/replacement/flags is the a sed command, described in detail in man sed In this case, pattern is a regular expression Replacement is what that pattern gets replaced with when/where found And flags describe details about how that replacement should be done. 51 sed is the stream editor
It can do a whole pile of really cool things, but the most common is text replacement The s,%,$,g part of the command line is the sed command to execute The s stands for substitute, the , characters are delimiters (other characters can be used How would i use sed to delete all lines in a text file that contain a specific string?
WATCH