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

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

Pergunta

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!

Foi útil?

Solução

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top