# Changing date format with script

**URL:** <https://community.unix.com/t/changing-date-format-with-script/367586>\
**Category:** UNIX for Beginners Q & A\
**Created:** [July 24, 2017, 6:39pm UTC](https://community.unix.com/t/changing-date-format-with-script/367586 "2017-07-24T18:39:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharat](https://community.unix.com/letter_avatar/sharat/32/5_5575768a8748004e209b776fc1b2916d.png) [@sharat](https://community.unix.com/u/sharat)\
**Post date:** [July 24, 2017, 6:39pm UTC](https://community.unix.com/t/changing-date-format-with-script/367586/1 "2017-07-24T18:39:33Z")

</div>

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

```nohighlight
#!/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.

```nohighlight
/ / 2017  
/ / 2017
/ /2017
/ / 2017

```

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [July 24, 2017, 7:02pm UTC](https://community.unix.com/t/changing-date-format-with-script/367586/2 "2017-07-24T19:02:13Z")

</div>

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

```nohighlight
od -tx1c file

```

.

---

<div class="post-metadata">

**Author:** ![sharat](https://community.unix.com/letter_avatar/sharat/32/5_5575768a8748004e209b776fc1b2916d.png) [@sharat](https://community.unix.com/u/sharat)\
**Post date:** [July 24, 2017, 7:05pm UTC](https://community.unix.com/t/changing-date-format-with-script/367586/3 "2017-07-24T19:05:48Z")

</div>

Thanks for reply.

Here is the screenshot of the output I get

> [@rudic](#):
>
> 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
> 
> ```plaintext
> od -tx1c file
> 
> ```
> 
> .

---

<div class="post-metadata">

**Author:** ![apmcd47](https://community.unix.com/letter_avatar/apmcd47/32/5_5575768a8748004e209b776fc1b2916d.png) [@apmcd47](https://community.unix.com/u/apmcd47)\
**Post date:** [July 25, 2017, 3:28am UTC](https://community.unix.com/t/changing-date-format-with-script/367586/4 "2017-07-25T03:28:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sharat](https://community.unix.com/letter_avatar/sharat/32/5_5575768a8748004e209b776fc1b2916d.png) [@sharat](https://community.unix.com/u/sharat)\
**Post date:** [July 25, 2017, 3:48pm UTC](https://community.unix.com/t/changing-date-format-with-script/367586/5 "2017-07-25T15:48:15Z")

</div>

Updated the output , can you please let me know

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/5_5575768a8748004e209b776fc1b2916d.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [July 26, 2017, 4:09am UTC](https://community.unix.com/t/changing-date-format-with-script/367586/6 "2017-07-26T04:09:08Z")

</div>

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
