MorganR
MorganR

Reputation: 659

Use sed to discard anything before first backslash (\)

I have the following string. Note there's a blank space before '\\servername':

 \\servername\path\to\user with\spaces\sometimes

Or sometimes:

SomeInfo: \\servername\path\to\user with\spaces\sometimes

I'd like to use sed to remove anything before '\\servername'. I can do:

sed 's/SomeInfo\: //g'

But that doesn't always remove the leading space from the first example for some reason.

Upvotes: 0

Views: 41

Answers (1)

Peder Klingenberg
Peder Klingenberg

Reputation: 41085

sed 's/^[^\]*//' seems to do the trick for me.

Depends on having one instance per line. You didn't specify if that was the case.

Upvotes: 2

Related Questions