Bdfy
Bdfy

Reputation: 24621

How to delete substring from string?

I have a string:

09/May/2012:05:14:58 +0100

How to delete substring 58 +0100 from string ?

 sed 's/\:[0-9][0-9] \+0100//'

Not work

Upvotes: 1

Views: 8360

Answers (2)

paxdiablo
paxdiablo

Reputation: 881293

If they're always in that format, you can just do:

s/:[^:]*$//

This basically gets rid of everything beyond (and including) the final : character (colon, followed by any number of characters that aren't a colon, to the end of the line).

Upvotes: 0

KARASZI István
KARASZI István

Reputation: 31467

It does work:

echo "09/May/2012:05:14:58 +0100"|sed 's/\:[0-9][0-9] \+0100//'

Output:

09/May/2012:05:14

Upvotes: 3

Related Questions