iTry
iTry

Reputation: 135

sed delete line containing date

I have a file containing a huge (3400+ lines) list of URLs, each of which looks something like this:

http://examplesite/rn/index.php?PageID=SF01_02_01&ID=2015-12-23-0012

What I would like to do is use sed to select all lines containing today's date.

What I've been trying is:

datetoday=$(date +%Y-%m-%d)
sed "/$datetoday/!d" en.html

However, this seems to blank the file suggesting that no lines match the string. Any suggestions?

Upvotes: 1

Views: 1498

Answers (2)

Ed Morton
Ed Morton

Reputation: 203645

You could use GNU awk instead of 2 separate commands:

awk '$0~strftime("%F")'

Upvotes: 1

n4nn31355
n4nn31355

Reputation: 360

You can use flag p instead d:

sed -n "/$(date +%Y-%m-%d)/p" en.html

Upvotes: 2

Related Questions