0

I'm trying to use sed to do a fairly simple replace, but I can't figure out how to get it to do what I want. Here's what I want to do:

Given this block:

  ./crud/Dailies:
    path: ./crud/Dailies

I want to remove the ./*/ part, so the block ends up like this (while preserving whitespace):

  Dailies:
    path: Dailies

Can someone with more knowledge of sed give me a hand here?

HatLess
  • 10,622
  • 5
  • 14
  • 32

1 Answers1

2

Just replaccing the ./anything/ with noting should not be difficult:

sed -e 's/\.\/.*\///g' inputfile

see: https://regex101.com/r/161Xvn/1

Luuk
  • 12,245
  • 5
  • 22
  • 33
  • 2
    avoid the need for escaping `/` chars by using a different `/regex/repl/` delimiter, i.e. `'s:\./.*/::'` The `g` will have not effect, as the `.*` captures everything to the end of the line. Good luck to all. – shellter Jun 06 '23 at 18:03
  • Thanks so much @Luuk, this worked perfectly! – howsmydriving42 Jun 06 '23 at 18:25
  • When you might an absolute path (starting with `/`), match on the character after a space or start of line: `sed -r 's:(^| )\./.*/:\1:g' inputfile` – Walter A Jun 06 '23 at 18:30
  • 1
    @howsmydriving42 Look at https://stackoverflow.com/help/someone-answers and accept Luuks answer. – Walter A Jun 07 '23 at 19:34