This has probably been asked but the existing answers don't make sense to me. I am running a loop over multiple CSV files in a folder. This folder has non-csv files also and hence I must specify the csv files explicitly. I am modifying the csv files in several ways using awk, cut etc. After I am done, I want to redirect the output to new csv files with slightly modified names as follows:
TLC_2017.csv > TLC_2017_prepped.csv
Here's a MWE:
for file in TLC*.csv; do
cut -d, -f2- ${file} > ${file}_prepped
done
The problem is that I am getting new files with names such as TLC_2017.csv_prepped
. In other words, the suffix is being added to the file extension and not the name. How do I add the suffix to the filename and not the extension?
If an answer to an existing question solves my problem, kindly don't just link to it but also provide a little bit of explanation so that I can figure it out. Thanks!