Unix/Linux Go Back    



Remove the leading and trailing date from a CSV file

Shell Programming and Scripting




Kindly Note - This is a Single User Post by Forum Member shivamayam Regarding:
Remove the leading and trailing date from a CSV file.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 07-13-2017
shivamayam shivamayam is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 11 October 2017, 12:51 PM EDT
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
I'm using a shell script. I have extracted today files to a directory1 and date should be removed on both sides of a CSV file.

FYI... I'm looking to remove the date from the file name and not inside the CSV file.

Directory1

2017-07-12_gmr_tag_log_20170711.csv
2017-07-12_gmr_call_log_20170711.csv
2017-07-12_gmr_outgoing_log_20170711.csv

Final output Directory2:

gmr_tag_log.csv
gmr_call_log.csv
gmr_outgoing_log.csv

---------- Post updated at 09:30 AM ---------- Previous update was at 03:52 AM ----------

I used the below script and it removed the trailing date. How to remove the leading date ?

ls -1 *.csv | awk '{print "mv " $1 " final/"$1}' | sed -E 's/([[:alpha:]]+)_[^_]+(\.csv)/\1\2/2' | csh

Any help is much appreciated.

Last edited by shivamayam; 07-13-2017 at 07:33 AM..