#!/bin/bash #----------------------------------------------- # Searches for a pattern among Internet Drafts # whose name contains a string. # # For example, search all drafts with 'geopriv' # in name for those that contain 'GPS'. # #----------------------------------------------- # # Version 1.0 # June 15, 2011 # Randall Gellens # #----------------------------------------------- #----------------------------------------------- # Verbose messages #----------------------------------------------- function say () { if [ "${opt_verbose}" = "y" ]; then echo "$1" fi } function vsay () { if [ "${opt_super_verbose}" = "y" ]; then echo "$1" fi } #----------------------------------------------- # Start of main script #----------------------------------------------- #!/bin/bash #----------------------------------------------- # Opens an I-D from the I-D directory. If not # present, tries to fetch it first. May fetch # and open multiple matching documents. #----------------------------------------------- # # Version 1.3 # Mrch 26, 2009 # Randall Gellens # #----------------------------------------------- #----------------------------------------------- # Verbose messages #----------------------------------------------- function say () { if [ "${opt_verbose}" = "y" ]; then echo "$1" fi } function vsay () { if [ "${opt_super_verbose}" = "y" ]; then echo "$1" fi } #----------------------------------------------- # Start of main script #----------------------------------------------- #!/bin/bash #----------------------------------------------- # Opens an I-D from the I-D directory. If not # present, tries to fetch it first. May fetch # and open multiple matching documents. #----------------------------------------------- # # Version 1.3 # Mrch 26, 2009 # Randall Gellens # #----------------------------------------------- #----------------------------------------------- # Verbose messages #----------------------------------------------- function say () { if [ "${opt_verbose}" = "y" ]; then echo "$1" fi } function vsay () { if [ "${opt_super_verbose}" = "y" ]; then echo "$1" fi } #----------------------------------------------- # Usage instructions #----------------------------------------------- function usage () { ME=$(basename $0) echo "usage: $ME [flags] "; echo " Use quotes for grouping" echo "Flags: -i Ignore case when matching" echo " -o Open matching drafts (by calling open_id)" echo " -v Verbose mode" echo " -V Super verbose mode" echo " -w Look for whitespace ('\W') around pattern" echo "Example: $ME -v -w \"gps\" \"geopriv ecrit\"" echo " Looks for drafts with \"geopriv\" or \"ecrit\" in name and the word \"gps\" in body." } #----------------------------------------------- # Start of main script #----------------------------------------------- cd ~/IETF/Internet_Drafts if [ $# -eq 0 ]; then usage exit -1; fi opt_verbose="n" opt_super_verbose="n" opt_open="n" opt_word="n" opt_case="n" open_id_opt_str="" grep_opt="" warn_count=10 while getopts ":iovVw" opt do case $opt in i) echo "Ignoring case when matching" opt_case="y" grep_opt="$grep_opt -i" ;; o) echo "Will open matching drafts (using open_id)" opt_open="y" ;; v) opt_verbose="y" echo "Verbose mode" open_id_opt_str="${get_id_opt_str} -v" ;; V) opt_verbose="y" opt_super_verbose="y" open_id_opt_str="$open_id_opt_str -V" echo "super verbose mode" ;; w) echo "Using word matching (whitespace around pattern)" opt_word="y" grep_opt="$grep_opt -w" ;; *) echo "Unrecognized option: ${opt}" exit ;; esac done shift $(($OPTIND - 1)) vsay "Params ($#): $@" if [ $# -lt 2 ]; then usage exit -1; fi name_pat="$1" grep_pat="$2" say "Looking for I-Ds with names matching: $name_pat" say "and contents matching: $grep_pat" target_draft_count=0 target_drafts=$(list_id $name_pat) for idx in $target_drafts do let target_draft_count++ done say "list_id found $target_draft_count draft(s)" vsay "**********" vsay "Drafts to be searched: $target_drafts" vsay "**********" matching_draft_count=0 vsay "grep $grep_opt -l \"$grep_pat\" $target_drafts" vsay "**********" matching_drafts=$(grep $grep_opt -l "$grep_pat" $target_drafts) for idx in $matching_drafts do let matching_draft_count++ done say "grep found $matching_draft_count matching draft(s)" if [ "$opt_open" = "y" ] && [ $matching_draft_count -ge $warn_count ]; then bOpen="gork" while [ "$bOpen" != "n" ] && [ "$bOpen" != "y" ]; do echo -n "Really open $matching_draft_count drafts? :" read bOpen done opt_open=$bOpen fi if [ $matching_draft_count -gt 0 ]; then if [ "$opt_open" = "y" ]; then say "calling open_id for $matching_drafts" open_id $open_id_opt_str $matching_drafts else echo "$matching_drafts" fi else echo "No matching drafts found" fi