Re: [SLUG] text processing

From: Eben King (eben01@verizon.net)
Date: Thu Sep 18 2008 - 11:09:17 EDT


On Thu, 18 Sep 2008, blee2@tampabay.rr.com wrote:

> Thus Eben King hast written on Wed, Sep 17, 2008 at 08:52:20PM -0400, and, according to prophecy, it shall come to pass that:
>>> home/mp3/A
>>>
>>> with
>>>
>>> home/mp3/a/A
>>
>> Yes, in the case of Aphex_Twin and Abbot_+_Costello and all those "A"
>> groups. But for the rest, would I have to do something similar 26 times?
>> Or is there a regexp form that means "insert lowercase(#1) at #2"?
>>
>> /home/eben/mp3/_/_...
>
> Something I've done in similar cases where I want to build a listing of an entire directory is:
>
> find /home/mp3 > ~/foo.m3u
> vi ~/foo.m3u #edit appropriately

Sure, I did something like that to start off, and it's good for making a
playlist of _all_ the files. However, as I was making some
special-purpose m3us, I then weeded out files that didn't meet the
criterion.

> # Of course this will have to be modified if there are many, many files
> # Should sort in local sort order.
> for i in "/home/mp3/*/*"
> do
> echo '<a href='$i'>'$i'</a> <br>' >> ~/foo.m3u
> #Not sure why we're building links to mp3 files, but why not.
> done

Maybe I could do something like this, taking input from the existing file,
and use standard text-processing tools to do my dirty work, and not have to
figure out the vim syntax. Something like

while read line ; do
     case "$line" in
         /*) firstchar=$(sed ...)
             capitalchar=$(...)
             echo "$line" | sed ".../mp3/$capitalchar/..." ;;
         *) echo "$line" ;;
     esac
done < existing.m3u > test.m3u

Good thing I'm not on a slow computer. Iterating through lines is to be
avoided. Better if I can rig sed to process the whole file in one run.
Hmm, might something like this do:

sed -e "/^#/n" -e "/^\\//s@/mp3/\\(.\\)$@/mp3/?/\\1@"

The thingy for lowercasing a letter goes in place of the '?'. But that's as
bad as the vim problem, s/vim/sed/, since I don't know how to do that.

-- 
-eben    QebWenE01R@vTerYizUonI.nOetP    royalty.mine.nu:81
PISCES:  Try to avoid any Virgos or Leos with the Ebola
virus. You are the Lord of the Dance, no matter what those
idiots at work say.  -- Weird Al, _Your Horoscope for Today_
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS).  Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 16:58:16 EDT