#!/bin/sh if [ $# -lt 3 ] ; then echo -e "\nUsage: ./search-posts.sh d|c user string [file]\n" exit fi if [ "$1" == "d" ] ; then type="Diary" elif [ "$1" == "c" ] ; then type="comment" else echo -e "\nType must be d or c\n" exit fi echo "type: $type" user="$2" find="$3" if [ $# == 4 ] ; then filename="$4" else filename=$(echo "$user" | sed 's/ /_/g') filename="$filename.txt" fi echo "filename: $filename" # check file exists: if [ ! -f "$filename" ] ; then echo -e "\nfile: $filename not found.\n" exit fi echo start="----------$type: $user ----------" finish="----------end $type: $user ----------" ./find-posts.awk -v start="$start" -v finish="$finish" -v find="$find" "$filename" > results.tmp count=$(grep -c "^$start" results.tmp) cat results.tmp # tidy up: # rm results.tmp echo echo "number of matching posts: $count"