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

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

Domanda

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!

È stato utile?

Soluzione

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top