Changing date format with script

I'm trying to change date format using this script from day/month/year to month/day/year

#!/bin/bash

while read line; do
echo "$line"
date=$(echo "$line" | cut -d/ -f1 )
month=$(echo "$line" | cut -d/ -f2 )
echo $month"/"$date"/2017"
done < ~/Downloads/Dates.csv

But I get output as //2017 instead of 03/02/2017(example) not sure why date and month field are not populated. Sample output.

/ / 2017  
/ / 2017
/ /2017
/ / 2017

Welcome to the forum.

Running your script on a file I get exactly what you want. So - is it possible the input file has invisible (control-) characters? Post the result of

od -tx1c file

.

Thanks for reply.

Here is the screenshot of the output I get

I didn't see your screenshot. Could you instead place your result between the code tags (the "CODE" button above the editing box), please?

Andrew

Updated the output , can you please let me know

As previously requested, please post the output (wrapped in CODE tags) from the command od -tx1c ~/Downloads/Dates.csv

Please add a new post to the thread rather than editing previous posts, because that can be very confusing when you try to read the conversation not knowing what has been changed.

Kind regards,
Robin

1 Like