2

I am working on a problem, As part of that I have got some 30,000 files with some content in it. What I want is that I want name:filename inside the file text, but since I have got so many files, it is not practical for me to go through each file and do it manually. Is there any way I can do it using shell?

$ cat file1
text1,text2

What I want is this:

$ cat file1
text1,text2
name:file1

I have written this code,

for i in `ls`; do echo $i >> $i; done;

What this is doing is that it is adding the file name as a string at the end, Is there any way I can add name:filename, instead of just filename.

2

If I understood you correctly you need

for i in *; do echo "name:$i" >> $i; done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.