• 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
egrep explanation needed
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

egrep explanation needed


  • Subject: egrep explanation needed
  • From: Marc <email@hidden>
  • Date: Sat, 03 Sep 2011 19:03:06 -0700

Hi All,

Could I impose on someone to explain this line to me?  Or at least point me in the right direction?

set theTxt to quoted form of (do shell script "curl '" & theURL & "' | egrep -A 17 'Full Address in Standard Format' | egrep -A 13 'height=\"34\"' | strings" without altering line endings)

I've Googled for the past 2 days and I can't decipher it for the life of me.  I'm trying to pull some lines of text from the returned HTML.  It works on the usps.com page it was written for, but I'd like to understand it so I can convert it to work with other pages as well.

These are some of the questions I have:

• Why are there two egrep commands?
• What does -A 17 and -A 13 mean?
• Are the pipes actually being used to pipe the lines, or do they just mean "or" in this situation?
• What does "strings" mean?


Here is the full script I found:

set theURL to "http://zip4.usps.com/zip4/zcl_0_results.jsp?visited=1&pagenumber=0&firmname=&address2=349C+Matawan+Road&address1=&city=Matawan&state=NJ&urbanization=&zip5=&submit=Find+ZIP+Code"

set theTxt to quoted form of (do shell script "curl '" & theURL & "' | egrep -A 17 'Full Address in Standard Format' | egrep -A 13 'height=\"34\"' | strings" without altering line endings)

set _street to (do shell script "echo -n " & theTxt & " | sed -n 2p | cut -d'<' -f 1")

set _csz to quoted form of (do shell script "echo " & theTxt & " | sed -n 3p | tr -d '\r\n' " without altering line endings)
set _city to (do shell script "echo " & _csz & " | cut -d'&' -f1")
set _state to (do shell script "echo " & _csz & " | cut -d';' -f2 | cut -c 1-2")

set _zipBoth to quoted form of (do shell script "echo " & _csz & " | cut -d';' -f4")
set _zip to (do shell script "echo " & _zipBoth & " | cut -c 1-5")
set _zip4 to (do shell script "echo " & _zipBoth & " | cut -c 7-")

Would there be a better way to write this code, or is it pretty good already?

Thanks!
Marc
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: egrep explanation needed
      • From: David Dantowitz <email@hidden>
  • Prev by Date: RE: INDESIGN: Updating Links Not Working
  • Next by Date: Re: egrep explanation needed
  • Previous by thread: Re: creation of Folders from File names
  • Next by thread: Re: egrep explanation needed
  • Index(es):
    • Date
    • Thread