Linux command: sed

From RHS Wiki
Revision as of 15:28, 19 June 2017 by Rafahsolis (talk | contribs)
Jump to navigation Jump to search

The sed command can be used for varius things see man page:
sed command man page
An example of use of sed to replace characters:
echo <string to replace> | sed <regular expression>
Regular expresion:

s -> replace.
g -> all the 'e' are replaced with 'R'. without g only one 'e' is replaced.
# -> delimitation character can be: {|, /, #}.

Example:

echo "esto es un ejemplo" | sed 's#e#R#g'

Replace New Line (\n) with ", "

sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/", "/g'