Issue
I have a bash variable $filename that looks like this
[rmerritt@server]$ echo $filename
/opt/project/xxxx/async_transaction__2023-05-28.csv
what I am hoping to do is extract that date stamp 2023-05-28 and store it in another bash variable $dateis that allows me to do this
cp /opt/project/xxxx/*`echo $dateis`*.csv|/opt/project/jdev/data/landing/landing_xxxx/
I.E. copy all csv files with that datestamp to another directory any idea how I could do this in a oneliner ? I have tried using awk
cp `ls -Art /opt/project/xxxx/*__*.csv` /opt/project/jdev/data/landing/landing_xxxx/
Solution
With GNU bash and its builtin parameter expansion:
filename="/opt/project/xxxx/async_transaction__2023-05-28.csv"
date="${filename##*_}"
date="${date%.*}"
echo "$date"
Output:
2023-05-28
Answered By - Cyrus Answer Checked By - Marilyn (WPSolving Volunteer)