Re: Reading files
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