0
I want to modify paths with a certain pattern.
For example
./foo/1023023/43655345/bar/
becomes
./foo/_dir_/_dir_/bar/
The pattern is always preceded by /foo/ followed by 2 directories that have numbers as a name (the strings to replace with the tag dir).
I tried using sed, but my regex skills aren't up to par with this problem. I don't get how to replace both directory strings with the tag.
This is actually exactly what I wanted. Do you know a good resource to learn regex? I looked at several tutorials online, but they all seem very incomplete. I'm new to cygwin in general. – Millianz – 2012-04-06T18:27:26.217
The canonical resource is Jeffrey Friedl's Mastering Regular Expressions; any online tutorial will be incomplete, simply because there is no single "regex" — it's a family of similar but not entirely compatible languages, and most tutorials focus on some particular regex implementation (usually Java or PHP in my experience, modern versions of which use PCRE).
sed
in particular uses POSIX basic regular expressions, which are much simpler (easier to learn, but often require more repetition). So it's hard to point at a good resource smaller than a fairly thick book. – geekosaur – 2012-04-06T18:41:01.150Hmm ok, I will look at some books in that case. How would I expand the above example when the numbers are in hex, i.e. 0-9,A-F are valid digits. – Millianz – 2012-04-06T19:05:39.477
That would be
[0-9A-F]
instead of simply[0-9]
. You may also want the-i
option if the digits might be either upper or lower case. – geekosaur – 2012-04-06T19:10:16.347Ok I see. I tried with a comma which didn't work. So if I wanted to ignore case I'd either do [0-9a-fA-F] or start sed with the -i option? – Millianz – 2012-04-06T19:17:17.527
Yes; either one would work (and both would be pointless). – geekosaur – 2012-04-06T19:19:42.403