Reputation: 670
I'm trying to use sed to delete a pattern from an html file. The time stamp consist of a 1-2 digit number a four letter word and then the word ago
example:
25 mins ago
or:
1 hour ago
and so on. I've tried using sed like this:
sed -i "s/([0-9]{1,2}) [a-z]* ago//g"
Sed does nothing, i'm not sure if my regex is wrong or if I am not escaping characters the right way.
Edit: I fixed that expression by removing an extra space, thanks choroba. Now sed removes mos of the text from the file. The expression needs to be less greedy? should also mention that ever time stamp is surrounded by > <
example:
>1 hour ago<
Edit: This is what worked for me. Thanks ravoori.
sed -i 's/[0-9]\{,2\} [[:alpha:]]\{4,5\} ago//g'
Any help is appreciated!
Upvotes: 1
Views: 2393
Reputation: 23364
Try the below. You need to escape the quantifier metacharacters {
and }
with sed
echo "1 hour ago" | sed 's/[0-9]\{,2\} [[:alpha:]]\{4\} ago//g'
Upvotes: 3
Reputation: 11479
echo "1 hour ago" | sed -e 's/.*ago$//g'
or
sed -e 's/.*ago$//g' <filename>
This should remove any line that ends with ago
in filename
You may not want to use this if you have other lines than just the timestamp that ends with ago
. You didn't specify.
Upvotes: 0