[Cialug] Regular Expression for Pathnames

Ron Houk houk.ron at gmail.com
Mon Nov 24 10:41:42 CST 2014


I guess the I put the sed in when I was thinking you wanted to look to text
towards the end of a path and have something like cut -d / -f 3- instead so
really the sed part isn't necessary now that i reread your email.

On Mon, Nov 24, 2014 at 10:40 AM, Ron Houk <houk.ron at gmail.com> wrote:

> You could truncate the file path | remove blank lines | and then search
> for the text with
>
> cut -d / -f -3 test | sed '/\n/d' | grep MyText
>
>
> where in cut f=Folder Depth+1
>
> On Mon, Nov 24, 2014 at 10:23 AM, Todd Walton <tdwalton at gmail.com> 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
>>
>
>


More information about the Cialug mailing list