warning warning warning This is a work-in-progress draft version.



sd

From github: sd:

sd is an intuitive find & replace CLI.

Installation

See sd: installation for details.

Search and replace

stdin example:

# note that all the occurrences are replaced
# first argument is the search text
# second argument is the replacement text
$ printf '1,2,3,4\na,b,c,d\n' | sd ',' '-'
1-2-3-4
a-b-c-d

$ echo 'I like "mango" and "guava"' | sd '"[^"]+"' 'X'
I like X and X

File example. By default, sd modifies the input in-place.

$ cat colors.txt
deep blue
light orange
blue delight

$ sd 'blue' 'green' colors.txt
$ cat colors.txt 
deep green
light orange
green delight

Use -p option to preview the results instead of in-place modification.

$ sd -p 'green' 'red' colors.txt
deep red
light orange
red delight

Fixed string substitution

Use -s option to treat the search and replace arguments as fixed strings.

# same as: sd 'in\+put' '$$a'
$ echo 'sample in+put' | sd -s 'in+put' '$a'
sample $a

Here's a multiline example:

$ cat ip.txt
This is a multiline
sample input with lots
of special characters
like . () * [] $ {}
^ + ? \ and ' and so on.
This post shows how
you can do fixed
-string multiline
search with cli tools.

$ sd -ps 'like . () * [] $ {}
^ + ? \ and' '====
----
====' ip.txt
This is a multiline
sample input with lots
of special characters
====
----
==== ' and so on.
This post shows how
you can do fixed
-string multiline
search with cli tools.




More to come