【发布时间】:2018-12-16 20:05:51
【问题描述】:
我有一个这样的 csv 文件:
DATE , Name , Description
2012181605 , Meeting , Business Meeting with John
1911181200 , Eating , Eating with my wife
日期以数字形式存储:在本例中,日期等于 20-12-2018 16:05。
我想创建一个 shell 脚本,用户可以在其中键入他想要预览的日期。在这种情况下,我想以某种方式仅提取前 6 个数字,它们仅指示日期而不是确切的时间。
这就是我到目前为止所尝试的。
#!/bin/bash
echo "type the date you want to preview"
read date1
if [ $(grep $date1 text.csv | wc -l) -eq 1 ];then
grep $date1 text.csv
elif [ $(grep $date1 text.csv | wc -l) -eq 0 ]; then
echo "the date you typed doesnt't exist or isn't valid
fi
【问题讨论】: