1

I have a bash script that I use for extracting a set of data I need, and it works great when I am in the directory where the initial input file is.

#!/bin/bash 
sed -n '/FIRST KEYWORD/,/KEYWORD THAT STOPS SEARCH/p' initial_input.out >  tmp1.dat
sed -n '/SECOND KEYWORD/,/KEYWORD THAT STOPS SEARCH/p' tmp1.dat > tmp2.dat
awk '/parameter name/' spintmp2.dat

Effectively, I cut out the part of the file I need with sed and then use awk to get the lines associated with "parameter name". The reason I don't do awk right away is because the string "parameter name" is repeated many times in the initial_input.out file.

My output might look something like

parameter name    25.3  18.0  4.0 
parameter name    4.3   51.3  54.0
parameter name    1.3   1.4   1.5

Now I would like to do this for every initial input file in all subdirectories. For example I am in a directory that contains subdirectories named "one", "two", and "three", each containing their own initial input file (which can be represented as *.out).

How can I run this script from my current directory, and receive the output from all subdirectories at once, knowing which output is coming from which subdirectory?

Thank you.

1 Answer 1

1

perhaps loop over the result of find:

find . -name "*.out" | while read path; do
    echo "The path is $path"
    # do stuff
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.