rfclookup (1348B)
1 #!/bin/sh 2 # 3 # rfclookup.sh 4 # Created by Hayden Hamilton 5 # 6 # hayden@haydenvh.com 7 # Copyright (c) 2020 Hayden Hamilton 8 # 9 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 11 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 12 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 13 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 14 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 15 # SOFTWARE. 16 # 17 # This work is free. You can redistribute it and/or modify it under the 18 # terms of the Do What The Fuck You Want To Public License, Version 2, 19 # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. 20 21 index=https://www.ietf.org/download/rfc-index.txt 22 document="https://tools.ietf.org/rfc/rfc%s.txt" 23 24 usage(){ 25 base=$(basename "$0") 26 printf "usage: %s -s <search query>\n" "$base" 27 printf "\t %s -n <number>\n" "$base" 28 printf "\t %s -u <number>\n" "$base" 29 } 30 31 case "$1" in 32 -s) 33 curl -Li $index | 34 tr '\n' '\t' | 35 sed 's/\t\t/\n/g' | 36 tr '\t' ' ' | 37 tr -s ' ' | 38 grep '^[0-9][0-9][0-9][0-9] ' | 39 grep -iE "$2" 40 ;; 41 -n) 42 curl -Ls $(printf "$document\n" "$2") | less 43 ;; 44 -u) 45 printf "$document\n" "$2" 46 ;; 47 esac