Re: Shell-sandwich a file in 2 variable strings
Re: Shell-sandwich a file in 2 variable strings
- Subject: Re: Shell-sandwich a file in 2 variable strings
- From: Christopher Nebel <email@hidden>
- Date: Thu, 5 Feb 2004 23:54:24 -0800
On Feb 1, 2004, at 2:52 AM, Chris Janton wrote:
If the HTML is just a single tag you can do
echo "TAG-OPEN" `cat somefile` "TAG-CLOSE" > some-file
which is one less process than "echo", "cat", "echo"
Riiiight. This works, but only for certain definitions of "works."
Because this passes the contents of the file as a parameter to echo(1),
it will break if somefile contains more than kern.argmax bytes (about
64K), and it modifies the contents slightly -- runs of white space will
turn into a single space. (This doesn't matter for HTML, though.)
Because of how Unix buffering works, it's also unsafe to use the same
file for both input and output -- you're likely to end up with less
data than you started with.
A safer version would be this:
(echo "TAG-OPEN"; cat somefile; echo "TAG-CLOSE") > otherfile
This is morally equivalent to Axel's suggestion (echo ... > other; cat
... >> other; echo ... > other), but only requires you to write "other"
once. For the curious, the parentheses cause the commands inside to be
executed in a sub-shell; the collective output is then stuffed into
otherfile, replacing the existing contents.
--Chris Nebel
AppleScript Engineering
_______________________________________________
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.