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

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

Question

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!

Était-ce utile?

La solution

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top