Running a command on all files in a folder and output same filenames, but in different location

StackOverflow https://stackoverflow.com/questions/19846904

سؤال

Sorry for my basic question, but I have >1000 text files in a folder. Is it a way of running the same command on all files and automatically output the new files to a different folder and giving them the same name as they had?

I.e.

grep 'something' path/to/file.txt > path/to-somewhere-else/file.txt

Thank you!

هل كانت مفيدة؟

المحلول

If all the files are in the same directory, it can be done easily by something like:

cd path/to
for i in *.txt; do grep 'something' "$i" >"path/to-somewhere-else/$i"; done
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top