2022-07-18 14:23:28 +02:00
|
|
|
#+options: toc:nil num:nil author:nil
|
|
|
|
|
2022-07-03 21:06:29 +02:00
|
|
|
* Using 'sed' to substitute text
|
|
|
|
|
|
|
|
"~sed~" is a stream editor for filtering and transforming text"...
|
|
|
|
|
|
|
|
This command in emacs editor
|
|
|
|
|
|
|
|
: M-x woman [RET] sed
|
|
|
|
|
|
|
|
Visits the following file with info about ~sed~
|
|
|
|
|
|
|
|
usr/share/man/man1/sed.1.gz
|
|
|
|
|
|
|
|
A brief example:
|
|
|
|
I have a long comma separated text file with strings and
|
|
|
|
need to include a line break after each comma (\n)
|
|
|
|
|
|
|
|
: cat filetest
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
|'string1',|'string2', |'string3'|
|
|
|
|
|
|
|
|
Using ~sed~ and redirecting the output to "filetest1"
|
|
|
|
|
|
|
|
: $ sed 's/\,/&\n/g' filetest > filetest1
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
| 'string1', |
|
|
|
|
| 'string2', |
|
|
|
|
| 'string3' |
|
|
|
|
|