-3

I have a question: how to replace forward slashes with backslashes?

I have string:

App/Models

And I need

App\Models

Thank you very much

AdminBee
  • 21,637
  • 21
  • 47
  • 71
Alexey Bob
  • 1
  • 1
  • 1

2 Answers2

3

Try this (in e.g. bash),

string="App/Models"
echo "${string//\//\\}"

or if you don't have it as variable, you can use tr:

printf '%s\n' "App/Models" | tr '/' '\'
Kusalananda
  • 320,670
  • 36
  • 633
  • 936
pLumo
  • 22,231
  • 2
  • 41
  • 66
  • It's a bit tough to parse out what's happening here among the mess of '\' and '/', it would be helpful to break down the pieces of the substitution, or point to some documentation where we could read about substitutions (I'm finding it a bit hard to find such documentation) – MichaelChirico Mar 16 '23 at 00:35
0
$ printf '%s\n' "App/Models" | sed -e 's|/|\\|g'
App\Models
  • Use `y///` rather than `s///g` to change single characters globally in `sed`, it's much more efficient. In this case, the `tr` utility would have been a better fit though. – Kusalananda May 27 '20 at 19:02