# parse variable

**URL:** <https://community.unix.com/t/parse-variable/168012>\
**Category:** Shell Programming and Scripting\
**Created:** [January 3, 2007, 5:24am UTC](https://community.unix.com/t/parse-variable/168012 "2007-01-03T05:24:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpang](https://community.unix.com/letter_avatar/mpang/32/5_5575768a8748004e209b776fc1b2916d.png) [@mpang](https://community.unix.com/u/mpang)\
**Post date:** [January 3, 2007, 5:24am UTC](https://community.unix.com/t/parse-variable/168012/1 "2007-01-03T05:24:00Z")

</div>

I have a variable (it is a date actually -\> 2007-01-03) which  
would be passed in as parameter, what I want is to parse in and put  
year, month, and day in separate variables, I have tried the following  
but doesn't work

```
echo $dt | awk -F- '\{print $1 $2 $3\}' | read y m d

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![anbu23](https://community.unix.com/user_avatar/community.unix.com/anbu23/32/351_2.png) [@anbu23](https://community.unix.com/u/anbu23)\
**Post date:** [January 3, 2007, 5:34am UTC](https://community.unix.com/t/parse-variable/168012/2 "2007-01-03T05:34:40Z")

</div>

```nohighlight
var1=$( echo $dt | cut -d"-" -f1 )

```

---

<div class="post-metadata">

**Author:** ![vino](https://community.unix.com/user_avatar/community.unix.com/vino/32/156_2.png) [@vino](https://community.unix.com/u/vino)\
**Post date:** [January 3, 2007, 6:31am UTC](https://community.unix.com/t/parse-variable/168012/3 "2007-01-03T06:31:11Z")

</div>

Without awk or cut...

```nohighlight
echo "$dt" | while IFS="-" read y m d
do
echo $y
echo $m
echo $d
done

```
