• 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: Reading files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading files


  • Subject: Re: Reading files
  • From: "Mark J. Reed" <email@hidden>
  • Date: Wed, 19 Oct 2005 09:24:06 -0400

In the shell world, you have a variety of tools for extracting specific desired lines from text files, since most of the configuration files in UNIX are based on this principle.  Which tool to use depends on how you identify the desired lines (by content or position) and what you want to do with them once you've picked them out.  sed is a good choice for extracting a block of lines from the middle of a file if you know the line numbers:

sed -ne ${line1},${line2}p filename

that is, `sed -ne 13,20p`  will extract lines 13 through 20. If you have multiple non-contiguous blocks of lines, you can print them all out with a single call to sed like this:

sed -ne 13,20p -e 2p -e 102,136p  filename

That will print line 2, lines 13 through 20, and lines 102 through 136.  Note no matter what order you specify the line numbers in, the lines are always output in the order in which they appear in the file, since sed makes only one pass.
Also, the output will be all lumped together with no easy way to tell where one block stops and another starts.  If those aspects aren't acceptable for your application, you may have to make multiple calls to sed, but at that point the overhead of "do shell script" will really start to bite you and you might want to think about just slurping the entire file contents into AS memory all at once as one big string and manipulating it that way.


--
Mark J. Reed <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

References: 
 >Re: Reading files (From: Shane Stanley <email@hidden>)
 >Re: Reading files (From: Malcolm Fitzgerald <email@hidden>)

  • Prev by Date: Re: Days and hours
  • Next by Date: Re: Applescript-users Digest, Vol 2, Issue 687
  • Previous by thread: Re: Reading files
  • Next by thread: Re: Reading files
  • Index(es):
    • Date
    • Thread