Reputation: 13
I have a range of directories from 2010 to 2017 and a sub-directory in them from 1 to 12. There is a file in each sub-directory, I need to add a line to each of these files.
This is part of my script:
#!/bin/bash
mkdir -p test/201{0..7}/{1..12}/
touch test/201{0..7}/{1..12}/file_{0..9}.txt
Upvotes: 1
Views: 54
Reputation: 141
In your script, it was created a range of directories from 2010 to 2017 and a range of sub-directories that goes from 1 to 12 in each directory. You also created nine files in each sub-directory at the end.
So, to append a new line in each of these files you should use the echo
command to create the contents of your line and redirect it to the tee
command to add it to all your files at once, as follows:
echo "new line" | tee -a test/201{0..7}/{1..12}/file_{0..9}.txt
That should be enough.
Upvotes: 0
Reputation: 88644
echo "42" | tee test/201{0..7}/{1..12}/file_{0..9}.txt
Append to files:
echo "42" | tee -a test/201{0..7}/{1..12}/file_{0..9}.txt
Upvotes: 1