• 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: Shell-sandwich a file in 2 variable strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Shell-sandwich a file in 2 variable strings
      • From: Michael Terry <email@hidden>
References: 
 >Re: Shell-sandwich a file in 2 variable strings (From: Chris Janton <email@hidden>)

  • Prev by Date: Re: Calculate Sunrise, Sunset?
  • Next by Date: Re: Command Line Fix for Locked Files?
  • Previous by thread: Re: Shell-wrap a file in 2 variable strings
  • Next by thread: Re: Shell-sandwich a file in 2 variable strings
  • Index(es):
    • Date
    • Thread