• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Piping sed to sed commands
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Piping sed to sed commands


  • Subject: Re: Piping sed to sed commands
  • From: BJ Terry <email@hidden>
  • Date: Sat, 17 Jan 2004 12:47:11 -0800

On Jan 17, 2004, at 7:30 AM, Gnarlodious wrote:

Apple continually adds new elements to iTunes' database, but I only want 7
of them:
Name Artist Album Genre Size Year Comments

Is there a way in sed/regex to only print these lines dropping the rest? If
not, I can use your above solution piping 7 commands together, but it seems
like a kludge.

I put quotes around the classes
too, I'm not sure if that is necessary
No, it's not in modern browsers, and neither
is the closing tag for cells "</td>".

-- Gnarlie

I don't believe that is possible in sed, since it doesn't support alternation i.e. (Album|Name|Artist). You can do it in perl instead, in which case the format of the regex changes a little bit. Here's a perl command to print just those categories:

perl -ne 'print while s/<key>(Name|Artist|Album|Genre|Size|Year|Comments)<\/ key><[^>]*>([^<]*)<\/[^>]*>/<td class=\1>\2/g'

that produces output like this from your test data:

<td class=Name>Rock Me Right
<td class=Artist>Susan Tedeschi
<td class=Album>Just Won't Burn
<td class=Genre>Rock Blues

It prints only the seven categories you were asking for. I'm going to leave escaping it for applescript as an exercise for the reader. I looked at your script, but I didn't have the opportunity to test it, since I don't have Tex-Edit. Good luck with it.


On Jan 17, 2004, at 4:18 AM, Chris Janton wrote:

do shell script "sed -e
's/.*<key>Name<\\/key><string>\\(.*\\)<\\/string>/<td class=Name>\\/' | sed
's/.*<key>Artist<\\/key><string>\\(.*\\)<\\/string>/<td class=Artist>\\/' "
& inPOSIX & ">" & outPOSIX


for one, shouldn't there be a "-e" for the second sed command?

for two - why not use a different character for your substitute command like

s|foo|bar|

instead of

s/foo/bar/

that way you don't get quite so many confusing escaped escape slashes

Good points all. I'm not an expert at using sed by any means. I started out using / as my delimiter, and it would've just been extra work to go back and change it later, unescaping the regex items I had already escaped. Hindsight is always 20/20.


BJ
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Piping sed to sed commands
      • From: Michael Terry <email@hidden>
References: 
 >Re: Piping sed to sed commands (From: Gnarlodious <email@hidden>)

  • Prev by Date: Re: piping sed to sed commands
  • Next by Date: Re: piping sed to sed commands
  • Previous by thread: Re: Piping sed to sed commands
  • Next by thread: Re: Piping sed to sed commands
  • Index(es):
    • Date
    • Thread