Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer

up vote 2 down vote accepted

If I understood you correctly you need

for i in *; do echo "name:$i" >> $i; done
share|improve this answer
 
yes that worked. –  Joe Dimaggio Nov 8 at 17:19
1  
@JoeDimaggio Note that it's for i in *; do …. Don't parse the output of ls. –  Gilles Nov 8 at 21:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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