Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串:
09/May/2012:05:14:58 +0100
如何58 +0100从字符串中删除子字符串?
58 +0100
sed 's/\:[0-9][0-9] \+0100//'
不行
它确实有效:
echo "09/May/2012:05:14:58 +0100"|sed 's/\:[0-9][0-9] \+0100//'
输出:
09/May/2012:05:14
如果它们始终采用这种格式,您可以这样做:
s/:[^:]*$//
这基本上消除了(包括)最后一个:字符(冒号,后跟任意数量的不是冒号的字符,直到行尾)之外的所有内容。
: