写简单工作记录的收获

written in bash, script, awk

Title: 写简单工作记录的收获

从shell读取键盘记录,读取单个字符,如果回车长度为0

read -n1 input
if [ ${#input} -eq 0 ]
then 
    category='工作'
else
    input=`expr $input - 1 `
    category=${comd[$input]}
fi 

gawk 删除重复文本

  1. 行用awk进行数据筛选
  2. sort 进行排序
  3. uniq 删除重复
gawk -F\| 'NR>2 {print $5}' ${file} | sort |uniq |gawk '{print NR"."$0}'

读取数据成为数组

comd_display=(`gawk -F\| 'NR>2 {print $5}' ${file} | sort |uniq |gawk '{print NR"."$0}'`)

for cc in ${comd_display[@]}
do
echo $cc
done

变量计算

i=0
for line in ${comd[@]}
do
    i=`expr $i + 1` #显示是加上序号 类似 i++
    echo $i.$line
done

读取系统时间,保存为变量

datetime=`date "+%Y-%m-%d %H:%M"`