在字符串中只打印出第一场 [英] Printing only the first field in a string
本文介绍了在字符串中只打印出第一场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个日期作为 12/12/2013 14:32
我想它转换成仅 12/12/2013
。
该字符串可以是 2013年1月1日12:32
或 2013年1月10日23:41
我只需要日期部分。
I have a date as 12/12/2013 14:32
I want to convert it into only 12/12/2013
.
The string can be 1/1/2013 12:32
or 1/10/2013 23:41
I need only the date part.
推荐答案
您可以轻松地与多种Unix工具做到这一点
You can do this easily with a variety of Unix tools:
$ cut -d' ' -f1 <<< "12/12/2013 14:32"
12/12/2013
$ awk '{print $1}' <<< "12/12/2013 14:32"
12/12/2013
$ sed 's/ .*//' <<< "12/12/2013 14:32"
12/12/2013
$ grep -o "^\S\+" <<< "12/12/2013 14:32"
12/12/2013
$ perl -lane 'print $F[0]' <<< "12/12/2013 14:32"
12/12/2013
这篇关于在字符串中只打印出第一场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文