I am using this code to read and print "file name" and "lines numbers", but the code can't read over 1 directory then stop without error msg?!
#!/bin/bash
find . -type d > mydirectory.txt
MyDir=mydirectory.txt
while read -r line; do
FileDir=$line/*.txt
for file in ${FileDir}
do
awk 'END{q="\047"; print "filename",", nlines"; print q FILENAME q "," q NR q}' "$file"
done > list.txt
done < mydirectory.txt
first line:
find . -type d > mydirectory.txt
get all directory and sub directory then save it in "mydirectory.txt".
then read every line in "mydirectory.txt" her:
while read -r line; do
FileDir=$line/*.txt
please what is the wrong, the code search in the first directory only! Regards
list.txt
with each iteration of thewhile
loop. It's unclear whether this is the only error (which you fix by moving the>list.txt
to after the lastdone
) or whether you mean something else with "the code can't read over 1 directory then stop without error". – Kusalananda Aug 27 '22 at 14:51For shell scripts with errors/syntax errors, please check them with the shellcheck program (or in the web shellcheck server at https://shellcheck.net) before posting here
– Ed Morton Aug 27 '22 at 15:42