0

what is

echo $PWD | sed 's?.*users/[^/]\+/??'

Here PWD is path :

/proj/SAM1/users/ssudi/SAm/VELOCE/ML3P8/trunk

what exactly sed command is doing here and how s?.*users/[^/]\+/?? this will work ?

New contributor
user226751 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2

s?.*users/[^/]\+/?? breaks down as follows:

  • s is the command of substitution
  • ? (all three of them) are expression separators (so the above might look like this as well: s@.*users/[^/]\+/@@). The general form is this: s/<match pattern>/<replacement>/<modifiers>. In this case there are no modifiers and no replacement in this substitution, so whatever is found by the first pattern will be removed from the stream.
  • .*users/[^/]\+/ is the search pattern and means:

    • .*whatever precedes users/
    • [^/]\+/ followed by something that's not \ (at least one such thing, possibly more) and these followed by one /.

    So it's targeting a string in a path that begins with users and is followed by one subfolder, eg. /subfolder/.

And thus what's left is this:

SAm/VELOCE/ML3P8/trunk

And here's the deleted part:

/proj/SAM1/users/ssudi/

/proj/SAM1/ preceded users/ and then followed ssudi.

Your Answer

user226751 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.