0

Rename a filetype in bash. So when the script runs, it intakes a csv file and outputs a excel file. I want the output excel file with the same name as input file without csv extension.

I have a bash code where i need some assistance.

bash Log2Time.sh 20190925_psort.csv
filename="${FILE%.*}"
mv Log2Timeline_Filtered.xlsx $filename_EventIDs.xlsx

The input for the script is 20190925_psort.csv I want the final output file i.e Log2Timeline_Filtered.xlsx to be renamed as 20190925_psort_EventIDs.xlsx

Shalabh
  • 27
  • 4
  • csv is a simple filetype and I think it's fair to say xlsx is not. The conversion of data can't simply be done by the extension. [Convert xlsx to csv in Linux with command line](https://stackoverflow.com/questions/10557360/convert-xlsx-to-csv-in-linux-with-command-line) may give you some ideas. – Neil Oct 21 '19 at 22:55

1 Answers1

2

How about this:

csv_file=20190925_psort.csv
touch Log2Timeline_Filtered.xlsx
mv Log2Timeline_Filtered.xlsx "${csv_file%.csv}_EventIDs.xlsx"

I simulated the conversion by just creating a new file called Log2Timeline_Filtered.xlsx. The answer removes the .csv suffix using parameter expansion. Look up parameter expansion in the bash man page to learn more about it.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Gorgor
  • 62
  • 1
  • 6