# get "%... .R" or "%... .xlsx" lines from tex file
grep -E '^\%.*\.R|.xlsx$' test.tex > R_files.txt

# if desired, get "%... .txt" lines and append
# grep -E '^\%.*\.txt$' test.tex >> R_files.txt

# Remove % from beginning of lines
sed -ie 's/% //g' R_files.txt
sed -ie 's/%//g' R_files.txt


# Remove space from beginning and end of lines
awk '{$1=$1};1' R_files.txt > R_files_2.txt

# Remove duplicate lines
sed '/^$/d' R_files_2.txt  | awk '!a[$1]++' > R_files_3.txt

# a small number of lines will require hand editing

# then run check_R_files
# eg
# ./check_R_files R_files_3.txt /Users/dsmith/Work/RH_pools_1 > main_ans.txt
