sharat
July 24, 2017, 6:39pm
1
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
RudiC
July 24, 2017, 7:02pm
2
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
.
sharat
July 24, 2017, 7:05pm
3
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
sharat
July 25, 2017, 3:48pm
5
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