Article 5E6E6 [SOLVED] Script - Grep part of Date String

[SOLVED] Script - Grep part of Date String

by
orangepeel190
from LinuxQuestions.org on (#5E6E6)
I am hoping for some assistance to try and get a portion of a script working.
The task that I am seeking assistance relates to a date string, namely in the format ddmmyyyy".

I am wishing to grep out the mm" component and check that against the current month (when the script is run) to ensure that both months match. I am wishing to extract the file from a curl dump to pull the correct file name based on its date string - namely from the month. The day - dd" - is likely to vary, and I am not really worried about the year, but happy to match the mmyyyy" part of the search if needed to obtain the correct file name.

If this is the case, it might actually be easier to remove the dd" part of the filename to extract and match the mmyyyy" component against the current mmyyyy" of when the script it run.

Eg:- Current month - 02 (being Feb)
Grep from date string on remote file - 02" - from a string similar to 12022021 (ddmmyyyy)

Where I am struggling is that in the past, I've normally had a - or / to seperate the date string apart. I was thinking something similar to:

month=$(date +%m')
year=$(date +%Y')
grep -E [0-9]+($month)+($year)'

Not sure if the [0-9] will cover single and two digit numbers?

I just wanted to run it past to ensure that the grep statement was correct to return the correct month from the search.

Failing that, is there a way I can cut the first digits of the date string to simply leave the mmyyyy" component?
If I was to cut" the dd" component - can that also happen?

I am having difficulties given that it doesn't not contain a separator and all the numbers are together.

Thank you for your assistancelatest?d=yIl2AUoC8zA latest?i=1T2P86YjzZs:Viz56kCF5Rw:F7zBnMy latest?i=1T2P86YjzZs:Viz56kCF5Rw:V_sGLiP latest?d=qj6IDK7rITs latest?i=1T2P86YjzZs:Viz56kCF5Rw:gIN9vFw1T2P86YjzZs
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments