Skip to content

Instantly share code, notes, and snippets.

@syui
Created September 7, 2014 16:51
Show Gist options
  • Save syui/cd6fd9765bf89644843d to your computer and use it in GitHub Desktop.
Save syui/cd6fd9765bf89644843d to your computer and use it in GitHub Desktop.
#!/bin/zsh
sfile=${0:a:t}
case $1 in
-[hH]|-[hH]elp)
echo "
引数1...ファイル名
引数2...キーワード1
引数3...キーワード2
$ ./$sfile httpd-access.log Moz Chr
"
;;
*)
case $# in
1)
cat $1
;;
2)
for i in `cat $1 | tr ' ' '\n' | nl -n ln | grep $2 | cut -d ' ' -f 1`;do cat $1 | cut -d ' ' -f $i- ;done
;;
3)
key1=`cat $1 | tr ' ' '\n' | nl -n ln | grep $2 | awk 'NR==1' | cut -d ' ' -f 1`
key2=`cat $1 | tr ' ' '\n' | nl -n ln | grep $3 | awk 'NR==1' | cut -d ' ' -f 1`
cat $1 | cut -d ' ' -f $key1-$key2
;;
*) echo no var;;
esac
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment