A few questions: I'm trying to use Bash (although I'm not against using AWK) to try to accomplish a few things, but I'm stumped on a few points.
I'm learning most of the basics quickly: but there are a few things I can't figure out.
1. I'm trying to count the number of .txt files in a directory and save it in a variable.
I can use
find $DIRECTORY -name *.txt | wc -l
but can't save that in a variable.
2&3. Is it possible to actually open these files (this will be a separate task entirely) and read a specific line? All of them are formatted the same, and I need to be able to read that line and save THAT to a list/array of variables- there are over 10,000 files- and I need the fourth line in each .txt. Many of these .txt files should have this line the same, so the array will never approach 10,000 - but I do need to be able to count how many times each appears- how would I do this?
(I know how to use loops, and create variables, but not open files (and read specific lines) nor make arrays/lists/whatever you call them in bash. <-Used to Java/Python; but can't use either here.
Any help with this is greatly appreciated- and I thank you for any help you can provide.
Last bit:
the files are all named similarly... 309456_20.txt
503256_01.txt
etc.
and all the files are in subdirectories named the same as the first three digits of the file.
So 309456_20.txt would be in subdirectory 309.
I'm not looking for a fast program or even a relatively efficient one; as long as it gets the job done.