Help with SED
Moderator: DosItHelp
Help with SED
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?
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
In case you were wondering:
sed -e "s/.*:\\[^\\]*\\\(\([^\\]*\\\)*\).*/\1/g" -e "s/\(.*\)\\$/\1/g"
works
sed -e "s/.*:\\[^\\]*\\\(\([^\\]*\\\)*\).*/\1/g" -e "s/\(.*\)\\$/\1/g"
works
Re: Help with SED
Any reason you need to use SED?
Re: Help with SED
I guess I have always used it and know the syntax pretty well. Is findstr similar or not as good?
Re: Help with SED
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?
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
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
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
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
Code: Select all
dir /AL /B /s
Re: Help with SED
Is this actually in your listing?
\??\
I don't see any of my junction points coming out like that at all.
\??\
I don't see any of my junction points coming out like that at all.
Re: Help with SED
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
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
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
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