Re: concatentate file name in batch



On 07.10.2010 05:31, ela wrote:
Is there any unix command that can add the file name to the first line of a
file?

I want to use the following script to add headers in batch

#!/bin/sh
#set -x

for i in `ls $1`
do

concatenate_file_name $i

done


e.g. input files in directory TEST

a.txt
b.txt

a.txt:
I am a boy

b.txt
you are a girl

==>

a.txt.modified
a.txt
I am a boy

b.txt.modified
b.txt
you are a girl




#!/bin/bash
for i in `ls $1`
do
cat $i > temp #save data
echo $i > $i #write filename to file
cat temp >> $i #append data to file
done
rm temp

I think there are better ways, but this would work!

.



Relevant Pages

  • Re: concatentate file name in batch
    ... I want to use the following script to add headers in batch ... almost everyone gets busy on the proof. ...
    (comp.os.linux.misc)
  • Re: concatentate file name in batch
    ... I want to use the following script to add headers in batch ... e.g. input files in directory TEST ...
    (comp.os.linux.misc)
  • Re: making a script
    ... batch command: executed successfully. ... I have used gimp's batch processing only slightly, ... You are using the batch mode to execute a scheme script ...
    (comp.graphics.apps.gimp)
  • Re: How to Get Local Variables That Are Not So Local
    ... variable is but the batch it is defined in. ... At least, not in SQL Server 2000, but they ... script, ... You could do your object definitions plainly ...
    (comp.databases.ms-sqlserver)
  • Re: UNIX tr utility written in vbscript
    ... Does anyone have a trick of combining a batch ... > A batch file can run a VBScript program, and you can pass the name of> the ... > Example.vbs with the following command: ... write a batch script that creates the vbscript file to be called. ...
    (microsoft.public.scripting.vbscript)