我有这个 :
2018:01:02-23:52:48
2018:01:02-23:52:48
2018:01:02-23:52:48
2018:01:03-09:26:20
2018:01:03-09:26:20
Run Code Online (Sandbox Code Playgroud)
我想保留日期,而不是小时,以便对每天的消息数进行排序:
2018:01:02
2018:01:02
2018:01:02
2018:01:03
2018:01:03
Run Code Online (Sandbox Code Playgroud)
awk如果可能的话,我想这样做。
jim*_*mij 13
awk
awk -F- '$0=$1' file
Run Code Online (Sandbox Code Playgroud)切
cut -d- -f1 file
Run Code Online (Sandbox Code Playgroud)sed
sed 's/-.*//' file
Run Code Online (Sandbox Code Playgroud)perl
perl -pe 's/-.*//' file
Run Code Online (Sandbox Code Playgroud)只需awk:
awk -F'-' '{ print $1 }' file
Run Code Online (Sandbox Code Playgroud)
-F'-'- 将-(破折号)视为字段分隔符但在你的简单情况下,grep方法会更简单:
grep -o '^[^-]*' file
Run Code Online (Sandbox Code Playgroud)