Page 1 of 2

Help with SED

Posted: 31 Mar 2014 05:55
by ferrad
If anyone knows SED syntax, can they help? I have a bit of text:

Dev\TechRefactoring\BOPVT]

where there can be any number >=1 occurrences of the \ before \BOPVT. I am trying to remove the last \BOPVT to obtain only:

Dev\TechRefactoring

It's easy if there is only 1 \, but if the number is variable how do get all but the last removed?

Re: Help with SED

Posted: 31 Mar 2014 06:09
by ferrad
In case you were wondering:

sed -e "s/.*:\\[^\\]*\\\(\([^\\]*\\\)*\).*/\1/g" -e "s/\(.*\)\\$/\1/g"

works

Re: Help with SED

Posted: 31 Mar 2014 06:14
by Squashman
Any reason you need to use SED?

Re: Help with SED

Posted: 31 Mar 2014 06:19
by ferrad
I guess I have always used it and know the syntax pretty well. Is findstr similar or not as good?

Re: Help with SED

Posted: 31 Mar 2014 06:22
by ferrad
Here is what I need to do. I have:

31/03/2014 12:07 <JUNCTION> BOPVT [\??\d:\ReOTech\Dev\TechRefactoring\BOPVT]

I need to strip out everything before the 2nd backslash after d:, and everything after and including the last backslash, ie to get:

Dev\TechRefactoring

How do you do this in findstr?

Re: Help with SED

Posted: 31 Mar 2014 06:26
by Squashman
ferrad wrote:Here is what I need to do. I have:

31/03/2014 12:07 <JUNCTION> BOPVT [\??\d:\ReOTech\Dev\TechRefactoring\BOPVT]

I need to strip out everything before the 2nd backslash after d:, and everything after and including the last backslash, ie to get:

Dev\TechRefactoring

How do you do this in findstr?

So this example looks nothing like your first example. So first we need to understand how you are getting this output you have listed above.
I assume you are just using the DIR command. If you are, my question to you is why you are not using any of the switches to list only the bare format of the directory listing?

Re: Help with SED

Posted: 31 Mar 2014 06:48
by ferrad
Yes, straight from DIR. I need to determine if a directory is a JUNCTION or not. I don't know how to do this with any other DIR options.

If it is, then I need to find out where it is pointing to, eg in the example:

d:\ReOTech\Dev\TechRefactoring\BOPVT

Then, once I have done that I need to strip everything except:

Dev\TechRefactoring

Re: Help with SED

Posted: 31 Mar 2014 06:56
by Squashman

Code: Select all

 dir /AL /B /s

Re: Help with SED

Posted: 31 Mar 2014 07:04
by Squashman
Is this actually in your listing?
\??\

I don't see any of my junction points coming out like that at all.

Re: Help with SED

Posted: 31 Mar 2014 07:11
by goldfish
ferrad wrote:If anyone knows SED syntax, can they help? I have a bit of text:

Dev\TechRefactoring\BOPVT]

where there can be any number >=1 occurrences of the \ before \BOPVT. I am trying to remove the last \BOPVT to obtain only:

Dev\TechRefactoring

It's easy if there is only 1 \, but if the number is variable how do get all but the last removed?



what you need is gawk, not sed.

Code: Select all

echo "Dev\TechRefactoring\BOPVT" | gawk -F"\\" "$(NF)=\"\";1" OFS="\\"



Re: Help with SED

Posted: 31 Mar 2014 07:20
by foxidrive
This does it in GnuSED

Code: Select all

sed "s/.*:.[^\]*.\(.*\)\\.*/\1/"

Re: Help with SED

Posted: 31 Mar 2014 07:26
by foxidrive
goldfish wrote:what you need is gawk, not sed.


How are you Brian, it's been a while. How come you stopped using your other account?

Re: Help with SED

Posted: 31 Mar 2014 07:27
by Squashman
foxidrive wrote:
goldfish wrote:what you need is gawk, not sed.


How are you Brian, it's been a while. How come you stopped using your other account?

You beat me to it.

Re: Help with SED

Posted: 31 Mar 2014 07:28
by ferrad
Squashman wrote:

Code: Select all

 dir /AL /B /s


This doesn't show where they are pointing to.

Re: Help with SED

Posted: 31 Mar 2014 07:34
by ferrad
Squashman wrote:Is this actually in your listing?
\??\

I don't see any of my junction points coming out like that at all.


Yes that's how it shows in Windows 7