MakeTxt.all makes the files Txt.all by MakeTxt.all > Txt.all if you run awk '{if ($1 == "") d = $2; else print d " " $0}' < Txt.all > Txt.all.find you get a file that is more easily searchable for spelling errors. awk -f txt_to_search.awk < Txt.all > Txt.all.search gives a file that is searchable. You can then e.g. grep Jane Txt.all.search | sed 's/\(.*\)/tstval \1/' | cat - Txt.all.search | awk -f search_to_html.awk > Jane.html to get all pictures of Jane or grep -w waiter Txt.all.search | sed 's/\(.*\)/tstval \1/' | cat - Txt.all.search | awk -f search_to_html.awk > Jane.html to get all pictures of waiters To make sure that the PHOTO and /PHOTO tags balance, run awk -f check_photo_tags.awk < Txt.all To find all possible search terms, do (warning output is long) grep "" Txt.all.search | awk '{for (i = 2 ; i < NF ; i++ ) print $i}' | sort | uniq -c | sort -nr