Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Adding text to the beginning of a file
- Date: Fri, 16 Mar 2007 20:13:52 +0900
- From: "Arwyn Hainsworth" <arwynh@example.com>
- Subject: Re: [tlug] Adding text to the beginning of a file
- References: <45FA6B45.3040500@example.com>
On 16/03/07, Dave M G <martin@example.com> wrote:TLUG,
I'm writing a bash shell which will write today's date and some other info at the top of a bunch of PHP files.
I believe that ordinarily, the command "cat" is used for this. However, unless I'm mistaken, "cat" will always add text to the beginning of the file.
What I'll need to do is to over write some text up to a particular point.
So, if at the top of my PHP file it says:
# File modified 2007 03 16 # by Dave M G # --
Can I wipe out everything up to and including the "--" and then past in new text?
Sed is your friend:
sed '1,/^#--/ d' < file_with_data_to_replace > tmp_file cat file_with_new_data tmp_file > end_result_file
The 1st line deletes everything from line 1, up until it finds a '#--' at the start of the line. The 2nd line just pastes the new data together with the old.
A nice tutorial on sed can be found here: http://www.grymoire.com/Unix/Sed.html
Arwyn
PS Hello everyone! This is my first post to the list, yoroshiku.
- Follow-Ups:
- Re: [tlug] Adding text to the beginning of a file
- From: Stephen J. Turnbull
- Re: [tlug] Adding text to the beginning of a file
- From: Dave M G
- References:
- [tlug] Adding text to the beginning of a file
- From: Dave M G
Home | Main Index | Thread Index
- Prev by Date: [tlug] Adding text to the beginning of a file
- Next by Date: Re: [tlug] Adding text to the beginning of a file
- Previous by thread: [tlug] Adding text to the beginning of a file
- Next by thread: Re: [tlug] Adding text to the beginning of a file
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links