LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Write to multiple files...one command (https://www.linuxquestions.org/questions/linux-newbie-8/write-to-multiple-files-one-command-647004/)

tekmann33 06-04-2008 12:40 PM

Write to multiple files...one command
 
Here is the first type of job I have had to do where I am making additions to multiple files, and I was wondering what the best way to go about it is.

I have to write the same lines to multiple file, too many to do it manually.

The directory structure is this (directory names have been changed to protect the innocent):

/usr/local/abc/abc_1/file
/user/local/abc/abc_2/file
/usr/local/abc/abc_3/file
...
...
..

I want to make the same entry into "file" for all of files under "abc/abc_*/".

What would be the best and safest command to accomplish this?

colucix 06-04-2008 12:56 PM

You can try a for loop using the find command to list them, and edit the files one at a time. Or if you have simply to append some lines you can use tee, like this
Code:

echo line to append | tee /usr/local/abc/abc_?/file > /dev/null
the redirection to /dev/null is to prevent the terminal output. I wonder what are the original names of the directories...! ;)

pwc101 06-04-2008 01:00 PM

Quote:

Originally Posted by colucix (Post 3174741)
You can try a for loop using the find command to list them, and edit the files one at a time. Or if you have simply to append some lines you can use tee, like this
Code:

echo line to append | tee /usr/local/abc/abc_?/file > /dev/null
the redirection to /dev/null is to prevent the terminal output. I wonder what are the original names of the directories...! ;)

Would that not overwrite the files? Would
Code:

echo line to append | tee -a /usr/local/abc/abc_?/file > /dev/null
be more appropriate?

colucix 06-04-2008 01:02 PM

Yes, I had it in mind. Just forgotten. Thanks, pwc101 :)


All times are GMT -5. The time now is 12:39 PM.