At Mon, 8 Sep 2003 11:41:17 +0100, Karsten M. Self wrote: > > [1 <text/plain; us-ascii (quoted-printable)>] > on Mon, Sep 08, 2003 at 12:56:14PM +0800, csj ([EMAIL PROTECTED]) wrote: > > At Mon, 8 Sep 2003 01:58:43 +0100, > > Karsten M. Self wrote: > > > > > > [1 <text/plain; us-ascii (quoted-printable)>] > > > on Mon, Sep 08, 2003 at 12:33:39AM +0800, csj ([EMAIL PROTECTED]) wrote: > > > > Let's say I want to write a script that can convert the > > > > following: > > > > > > > > A-0001 Directory_1/Subdirectory_1/File_1.txt > > > > A-0002 ./Directory_2/Subdirectory_2/File_2.txt > > > > A-0003 ./Directory_3/Subdirectory_3/Subdirectory_4/File_3.txt > > > > > > > > to: > > > > > > > > A-0001 /Subdirectory_1/File_1.txt > > > > A-0002 /Subdirectory_2/File_2.txt > > > > A-0003 /Subdirectory_3/Subdirectory_4/File_3.txt > > > > > > > > My basic strategy would be to sed 's|/Directory_.||g'. > > > > Unfortunately this isn't of universal application. I'm looking > > > > for a solution than can take into account all possible names for > > > > "Dir_Foo". > > > > > > Based on what you've presented: > > > > > > sed -e 's/[ ]\.*\(\/Subdirectory_\)/ \1/' > > > > My brain is still trying to parse the slashes, but I take it to > > me that the trick is in the parenthesis()? Will try it when I > > get some sleep. Thanks! > > What it says is: substitute everything starting with the first > space or tab, any character, the string (which is preserved) > "/Subdirectory_", with a tab and the preserved string. > > Thinking about it, this might be better: > > s/[ ][^ ]*\(\/Subdirectory_\)/ \1/ > > Which says: tab, followed by non-whitespace characters...
Then this wouldn't work for the non-specific cases I have in mind. Both "Directory" and "Subdirectory" are variable. It can be ./Foo ./Dirfoo ./Pooh. I need to descend a certain number of subdirectories (/'s) down. BTW I just realized I have been using the regex forms you cited for a long time. In my .procmailrc! Thanks again. I'll try to approach the problem from a different perspective. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]