In a directory, I have 5000 multiple files that contains around 4000 rows with 10 columns in each file containing a unique string 'AT' located at 4th column.
OM 3328 O BT 268 5.800 7.500 4.700 0.000 1.400
OM 3329 O BT 723 8.500 8.900 3.600 8.500 1.400
OM 3330 O AT 231 6.700 5.500 7.600 0.000 1.400
OM 3331 O AT 234 1.200 7.700 5.500 8.500 1.400
OM 3332 O AT 256 3.800 5.800 5.200 0.000 1.400
I want to make a script to count how many 'AT' are found in each file, then print this count into a new file at second column. For example below, the 1st column represents the file number and the second column represents the counts. Since I have 5000 multiple files, I expect the first column to be 1....5000.
In the directory, the files are numbered in order and should be printed also in order accordingly into the new file. So in this case, file 1 should be read in first followed by file 2 and so forth until file 5000. How to make it that way?
The small problem was that the files are being read in random order, which is not the way the script should do for the counting. So for example:
Directory:
1.txt
2.txt
3.txt
.
.
.
5000.txt
Newfile:
1 5
2 0
3 8
4 2
5 2
6 0
7 3
8 5
9 0
10 1
Column 1, row1 is the first file (1.txt), column 1 row 2 is the second file (2.txt) and goes on until last 5000.txt