[Cialug] Regular Expression for Pathnames
Daniel A. Ramaley
daniel.ramaley at drake.edu
Mon Nov 24 10:34:19 CST 2014
This should work for your purposes if all the data looks like the
samples. Set the number between curly braces to whatever you need. (Note
that your sample data didn't have any matches for just 2 slashes, but
does for 3 slashes.)
egrep '^(/[^/]+){3}$'
On 2014-11-24 at 10:23:07 Todd Walton wrote:
> If I have a text file full of pathnames, like:
>
> /var/log/folder1
> /var/log/folder2
> /home/todd/mydir
> /var/log/folder1/fileh
> /var/log/folder1/foldersub/fileh
>
> ...etc, what's the regular expression to find where a string has
> exactly two (or however many) forward slashes to the left of it? I
> have a 360,000 line list of path names, and I'd like to find where a
> certain string falls early in the path. I'm really only interested
> in paths where it's in the top three or four directories.
>
> --
> Todd
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
__
Daniel A. Ramaley | Network Engineer 2
Drake Technology Services (DTS) | Drake University
T: +1 515 271-4540
F: +1 515 271-1938
E: daniel.ramaley at drake.edu
More information about the Cialug
mailing list