简体   繁体   中英

Removing date from the filename

I am working on a tool which accepts linux commands. I have files coming from differnt sources and i want to remove date from the file and tool supports '%F' ie absolute file name only.

%F is /Dir1/Subdir/ABC_20190101_PQR.csv
What I want is /Dir1/Subdir/ABC_PQR.csv

kindly help.

I tried some commands but none worked

I want /Dir1/Subdir/ABC_PQR.csv

mv %F {%F//_{0-9}//_{}}

Is this OK?

echo ${text} | sed -r 's/(.*)(_[[:digit:]]*_)(.*)/\1_\3/'

Example:

text="/Dir1/Subdir/ABC_20190101_PQR.csv"
echo ${text} | sed -r 's/(.*)(_[[:digit:]]*_)(.*)/\1_\3/'
/Dir1/Subdir/ABC_PQR.csv

This uses BASH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM