Dan Treacy wrote:

G'Day sluggers,

I have a text file that I'm trying to update from a shell script but the information needs to be inserted at the beginning of the file.

I have a couple of ways to do this that involves lots of "cat"ing and mving and temporary files and the like etc. Not real high on the efficiency scale.

So seeing as my scripting pretty much blows and it's been more than a day since we've had a my one-line-script-is-better-than-yours-fest I thought I'd put it to the masses.

shell (bash) solutions prefered. perl if you REALLY must :-)

Dan.


Is this script you have a ONE-TIME job, or is it RE-USED over-and-over again ?
If it is being RE-USED over-and-over again, how often ?


How ELEGANT do you want  this script to be ?

Let me just clarify, what your script does:

1. You have a script 'insert.sh' and text file called, 'myfile.txt'.
[~oscarp] $  cat myfile.txt
jumps over the
lazy dog near
the bank of
the river.

2. You run the script like so:
[~oscarp] $ insert.sh

3. Prompts you with:
Enter text to insert and <PRESS #> when completed.

<You enter> The quick brown fox #

4.  Your 'myfile.txt' becomes:
[~oscarp] $ cat myfile.txt
The quick brown fox
jumps over the
lazy dog near
the bank of
the river.

Is the above procedure what you have in mind or something else ?

The point of all these queries is will the end-results justify the time and effort
to achieve it ? And being narrower with the specifications.





-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to