I have 10 folders with consecutives name : book_1, book_2..... book_10 and each folder has a txt file named same as the folder. For example : book_1 has only book_1.txt and contains history material (only text).
I need to run an AWK script which output should be added by order to the output file. How can I generate a loop which runs through my folders and extractes the needed file from each folder?
awk '
{
script//
}
END { print "The output of book num $i is: " m }' book*/book*.txt >> output.txt // m is a variable which extracts max occurences of certain words which are set in the script
My output should look like this:
The output of book num 1 is : 123
The output of book num 2 is : 2223
and so on
thank you for your help!
find
andcat
. Hint: There a dozens of simple ways to achieve it.book_1/book_1.txt
(or better two files) in your question and explain where the numbers123
and2223
come from if it's not obvious.awk
doesn't really know how to open directories. The solution to your problem may be just to call it with the right arguments, eg.awk '...' book_?/book_?.txt book_??/book_??.txt
which will rely on the shell globbing to expand the file arguments in the right order.FILENAME==fn { fn = FILENAME; ... }
or via theFNR
variable. GNU awk also hasBEGINFILE
andENDFILE
similar toBEGIN
andEND
.