Pregunta

This command works, but I want it run it on every document (input.txt) in every subdirectory.

tr -d '\n' < input.txt | awk '{gsub(/\. /,".\n");print}' | grep “\[" >> SingleOutput.txt

The code takes the file input and divides it into sentences with new lines. Then it finds all the sentences that contain a “[“ and outputs the sentences to a single file. I tried several looping techniques with find and for loops, but couldn't get it to run in this example. I tried

for dir in ./*; do 
(cd "$dir" && tr -d '\n' < $dir | awk '{gsub(/\. /,".\n");print}' | grep “\[" >> /home/dan/SingleOutput.txt); 
done;

and also

find ./ -execdir tr -d '\n' < . | awk '{gsub(/\. /,".\n");print}' | grep "\[" >> /home/dan/SingleOutput.txt;

but they didn't work execute just giving me > marks. any ideas?

¿Fue útil?

Solución

Try this:

cd $dir
find ./ | grep "input.txt$" | while read file; do tr -d '\n' < $file | awk '{gsub(/\. /,".\n");print}' | grep “\[" >> SingleOutput.txt; done

This will find all files called input.txt under $dir, the it will perform what you say it's already working send output to $dir/SingleOutput.txt.

Otros consejos

Why not just something like this?

tr -d '\n' < */input.txt | awk '{gsub(/\. /,".\n");print}' | grep “\[" >> SingleOutput.txt

Or are you interested in keeping the output for each input.txt separate?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top