Skip to content

Instantly share code, notes, and snippets.

@tattyamm
Created July 28, 2012 15:35
Show Gist options
  • Save tattyamm/3193760 to your computer and use it in GitHub Desktop.
Save tattyamm/3193760 to your computer and use it in GitHub Desktop.
シェル操作練習
#!/bin/sh
# シェル操作課題 (cut, sort, uniq などで集計を行う) 設問編 - Yamashiro0217の日記
# http://d.hatena.ne.jp/Yamashiro0217/20120727/1343371036
# 問1
echo "---問1---"
cat Log.csv
# 問2
echo "---問2---"
while read LINE; do
STR1=`echo "${LINE}" | cut -d',' -f1`
STR2=`echo "${LINE}" | cut -d',' -f4`
echo $STR1,$STR2
done < Log.csv
echo "---問2 解2---"
awk -F , -v OFS=, '{ print $1,$4 }' Log.csv
# 問3
echo "---問3---"
cat Log.csv | grep "server4"
# 問4
echo "---問4---"
wc -l < Log.csv
# 問5
## http://d.hatena.ne.jp/a_bicky/20110724/1311497192
echo "---問5---"
sort -t , -k 1,1 -k 3,3n log.csv | head -5
# 問6
echo "---問6---"
sort log.csv | uniq | wc -l
# 問7
echo "---問7---"
awk -F , -v OFS=, '{ print $3 }' Log.csv | sort | uniq | wc -l
# 問8
echo "---問8---"
awk -F , -v OFS=, '{ print $4 }' Log.csv | sort | uniq -c | sort -r | head -1
# 問9
echo "---問9---"
awk -F , -v OFS=, '{ print $1 }' Log.csv | sort | uniq -c | sed -e "s/server/xxx/g"
# 問10
echo "---問10---"
awk -F , -v OFS=, '$3>=10{ print $3 }' Log.csv | sort | uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment