Or, if you want to prepend (at the beginning of the file), try
something like:

for i in * ; do cp $i $i.BAK ; (echo $i ; cat $i.BAK) > $i ; done

Will preserve file permissions and ownership.

Regards,

-- Raju

>>>>> "Sreeji" == Sreeji K Das <[EMAIL PROTECTED]> writes:

    Sreeji> On Fri, 5 Jan 2001, YL Narayana wrote:
    >> Hi.
    >> 
    >> I have a large number of small files. I need to insert/append
    >> the name of each file into the body of the file. How can I do
    >> it easily?
    >> 
    Sreeji> The simplest command line (in bash) would be:

    Sreeji> for i in * do echo -en $i >> $i; done

    Sreeji> That would append the filename to the file. Instead of '*'
    Sreeji> you can use any pattern. If you have directories while
    Sreeji> expanding '*', u'd see errors.

    Sreeji> If you want a still elegant solution, u can use perl. If u
    Sreeji> need a script, let me know.

    Sreeji> Sreeji
-- 
Raju Mathur          [EMAIL PROTECTED]           http://kandalaya.org/

----------------------------------------------
LIH is all for free speech.  But it was created
for a purpose.  Violations of the rules of
this list will result in stern action.

Reply via email to