NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
Intuitive find and replace CLI (sed alternative) (github.com)
flowingfocus 8 days ago [-]
For cases I am not 100% sure I want to replace all occurrences, I prefer scooter: https://github.com/thomasschafer/scooter
karmakaze 8 days ago [-]
The sed extraction example is more complicated than it needs to be:

    echo "sample with /path/" | sed -E 's|.*(/.*/)|\1|g'
The search/replace separator doesn't have to be '/'.

I can't see myself using this for a performance bump given that I already know vi, thus sed expressions.

sudahtigabulan 7 days ago [-]
The newline replacement stopped me in my tracks:

  sed ':a;N;$!ba;s/\n/,/g'
Nobody does that with sed, when there are way simpler alternatives, like paste and tr.
Myrmornis 8 days ago [-]
Regardless of the appeal to unix philosophy in their docs, sd has never stuck with me because it doesn't natively support replace across a project/ multiple files, and that's what you always want to do. Instead I pipe `rg -R --json` output into a script (rg does do replacement, but only on the stdout, not in-place)
mirashii 8 days ago [-]
I'm not sure I understand what you're saying. You can pass a list of files to sd, `sd before after **/*.py` to replace in all the python files in your project. That's about as native of a replace across multiple files you could possibly want.
assbuttbuttass 8 days ago [-]
Use find?

    find -exec sd before after \;
jiehong 8 days ago [-]
If you use fish, have a look at `string replace` as a built-in and related [0].

[0]: https://fishshell.com/docs/current/cmds/string.html

ctippett 8 days ago [-]
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 10:43:34 GMT+0000 (Coordinated Universal Time) with Vercel.