Help with SED

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
ferrad
Posts: 13
Joined: 28 Mar 2014 02:20

Help with SED

#1 Post by ferrad » 31 Mar 2014 05:55

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?

ferrad
Posts: 13
Joined: 28 Mar 2014 02:20

Re: Help with SED

#2 Post by ferrad » 31 Mar 2014 06:09

In case you were wondering:

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

works

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Help with SED

#3 Post by Squashman » 31 Mar 2014 06:14

Any reason you need to use SED?

ferrad
Posts: 13
Joined: 28 Mar 2014 02:20

Re: Help with SED

#4 Post by ferrad » 31 Mar 2014 06:19

I guess I have always used it and know the syntax pretty well. Is findstr similar or not as good?

ferrad
Posts: 13
Joined: 28 Mar 2014 02:20

Re: Help with SED

#5 Post by ferrad » 31 Mar 2014 06:22

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?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Help with SED

#6 Post by Squashman » 31 Mar 2014 06:26

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?

ferrad
Posts: 13
Joined: 28 Mar 2014 02:20

Re: Help with SED

#7 Post by ferrad » 31 Mar 2014 06:48

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

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Help with SED

#8 Post by Squashman » 31 Mar 2014 06:56

Code: Select all

 dir /AL /B /s

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Help with SED

#9 Post by Squashman » 31 Mar 2014 07:04

Is this actually in your listing?
\??\

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

goldfish
Posts: 10
Joined: 31 Mar 2014 07:02

Re: Help with SED

#10 Post by goldfish » 31 Mar 2014 07:11

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="\\"



foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with SED

#11 Post by foxidrive » 31 Mar 2014 07:20

This does it in GnuSED

Code: Select all

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with SED

#12 Post by foxidrive » 31 Mar 2014 07:26

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?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Help with SED

#13 Post by Squashman » 31 Mar 2014 07:27

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.

ferrad
Posts: 13
Joined: 28 Mar 2014 02:20

Re: Help with SED

#14 Post by ferrad » 31 Mar 2014 07:28

Squashman wrote:

Code: Select all

 dir /AL /B /s


This doesn't show where they are pointing to.

ferrad
Posts: 13
Joined: 28 Mar 2014 02:20

Re: Help with SED

#15 Post by ferrad » 31 Mar 2014 07:34

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

Post Reply