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: Sat, 17 Mar 2007 10:32:27 +0900
- From: Dave M G <martin@example.com>
- Subject: Re: [tlug] Adding text to the beginning of a file
- References: <45FA6B45.3040500@example.com> <ba75897e0703160413oc5219d7gb2bea3d53cd0afc2@example.com>
- User-agent: Thunderbird 1.5.0.10 (X11/20070306)
Arwyn,
Thanks for responding.Sed is your friend:
sed '1,/^#--/ d' < file_with_data_to_replace > tmp_file
cat file_with_new_data tmp_file > end_result_file
Thank you for the code and the link. I'm afraid that the tutorial left my head spinning a bit. I'm just learning bash shell syntax, and sed seems to have a whole new layer of options. I hope it's okay if I ask some more questions.
What I've learned is that this line in the above code: cat file_with_new_data tmp_file > end_result_file
... wipes out the whole tmp_file with the contents of file_with_new_data.
If I change it to: cat file_with_new_data tmp_file >> end_result_file
... then it adds the contents of file_with_new_data to the *end* of tmp_file. This is better, but actually, what I want to do is stick the data on at the beginning. Prepend, not append. I looked up command options for "cat" but couldn't find how to do it.
Other questions:
1. Can I use cat to prepend the contents of a variable in the shell script? I tried this:
TEXT="This is text"
cat $TEXT temp.file >> new.file
... but what it tried to do was look for three files called "This", "is", and "text" to append to the new file.
2. How do I execute this on multiple files? Like *.php, and .class?
-- Dave M G Ubuntu 6.10 Edgy Eft Kernel 2.6.20-5-generic Pentium D Dual Core Processor PHP 5, MySQL 5, Apache 2
- Follow-Ups:
- Re: [tlug] Adding text to the beginning of a file
- From: Scott Robbins
- Re: [tlug] Adding text to the beginning of a file
- From: Brett Robson
- Re: [tlug] Adding text to the beginning of a file
- From: Arwyn Hainsworth
- Re: [tlug] Adding text to the beginning of a file
- From: Stephen J. Turnbull
- References:
- [tlug] Adding text to the beginning of a file
- From: Dave M G
- Re: [tlug] Adding text to the beginning of a file
- From: Arwyn Hainsworth
Home | Main Index | Thread Index
- Prev by Date: Re: [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: Re: [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