• 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: How to parse a textfile ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to parse a textfile ?


  • Subject: Re: How to parse a textfile ?
  • From: Graff <email@hidden>
  • Date: Tue, 28 Sep 2004 10:56:19 -0400

The easiest way is probably to use regular expressions. The shell tool "grep" can do this for you, there are also some third-party OSAX that do regular expressions.

Here's how to do it using the shell tool "grep":
----
set theFile to choose file
set posixFile to quoted form of POSIX path of theFile
do shell script "egrep -A 1 '[[:digit:]]{3}-[[:digit:]]{2}-[[:digit:]]{2}' " & posixFile
----


Your line endings will have to be unix-style for this to work. Here is a slightly-modified version that will work with both Mac and Unix-style line endings:
----
set theFile to choose file
set posixFile to quoted form of POSIX path of theFile
do shell script "tr \"\\r\" \"\\n\" < " & posixFile & " | egrep -A 1 '[[:digit:]]{3}-[[:digit:]]{2}-[[:digit:]]{2}'"
----


- Ken

On Sep 28, 2004, at 9:43 AM, Stefan Eriksson wrote:

Greetings again !

I´m looking for an easy way to parse a textfile, i have a textfile with a load of rows, i´m only intrested in 2 of them and all i know is that those 2 are after the row after with date in format like 2004-09-15, xxxx-xx-xx

Looks like this in the textfile:

blah
blah
2004-09-15
00509562/00000147
11548
blah
blah

and i need to get this out:
2004-09-15
00509562/00000147

any suggestions, parsing text in AS seems lika a major pain...

Cheers, Stefan

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: How to parse a textfile ?
      • From: Joseph Weaks <email@hidden>
References: 
 >How to parse a textfile ? (From: Stefan Eriksson <email@hidden>)

  • Prev by Date: Re: Getting human-understandable time from iCal
  • Next by Date: Distinguish volumes with the same name?
  • Previous by thread: How to parse a textfile ?
  • Next by thread: Re: How to parse a textfile ?
  • Index(es):
    • Date
    • Thread