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



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



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links