Difference between revisions of "Linux command: sed"

From RHS Wiki
Jump to navigation Jump to search
m (Protected "Linux command: sed" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
Line 10: Line 10:
 
Example:
 
Example:
 
  <nowiki>echo "esto es un ejemplo" | sed 's#e#R#g'</nowiki>
 
  <nowiki>echo "esto es un ejemplo" | sed 's#e#R#g'</nowiki>
 +
 +
== Replace New Line (\n) with ", " ==
 +
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/", "/g'

Revision as of 15:28, 19 June 2017

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'