# Adding a timestamp every N row in another column

**URL:** <https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083>\
**Category:** Shell Programming and Scripting\
**Created:** [April 12, 2017, 7:53am UTC](https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083 "2017-04-12T07:53:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Board27](https://community.unix.com/letter_avatar/board27/32/6_449c533f586939b6e5f246632a46421f.png) [@Board27](https://community.unix.com/u/Board27)\
**Post date:** [April 12, 2017, 7:53am UTC](https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083/1 "2017-04-12T07:53:18Z")

</div>

Hi,  
i have a raw output file like this

```nohighlight
167,63.50

167,63.50

168,63.68

166,63.68

168,63.68

```

I would like to add every each N rows (for example 60) and in a third column , a timestamp using the command

```nohighlight
date +"%H:%M"

```

how can i do it with one single command ?

Thank you !!

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://community.unix.com/letter_avatar/ravindersingh13/32/6_449c533f586939b6e5f246632a46421f.png) [@RavinderSingh13](https://community.unix.com/u/RavinderSingh13)\
**Post date:** [April 12, 2017, 8:16am UTC](https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083/2 "2017-04-12T08:16:55Z")

</div>

Hello Board27,

Could you please try following and let me know if this helps you.

```nohighlight
 awk -v DATE=$(date +"%H:%M") -v var=3 'FNR%var==0{print $0,DATE;next} 1' Input_file

```

Here in above code I have given value of line as `3` you could change it to as per your need.

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![Board27](https://community.unix.com/letter_avatar/board27/32/6_449c533f586939b6e5f246632a46421f.png) [@Board27](https://community.unix.com/u/Board27)\
**Post date:** [April 12, 2017, 8:25am UTC](https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083/3 "2017-04-12T08:25:25Z")

</div>

it comes :

```nohighlight
314,63.14
 12:22

```

it is not adding a column with comma. Anyway i express myself in a wrong way. I don't need each N time. I just need to add timestamp at a certain line, for example, if my file has 1000 lines , add a timestemp to the 60th line, 3th column with comma divider.

Thank you anyway for your help!

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://community.unix.com/letter_avatar/ravindersingh13/32/6_449c533f586939b6e5f246632a46421f.png) [@RavinderSingh13](https://community.unix.com/u/RavinderSingh13)\
**Post date:** [April 12, 2017, 8:28am UTC](https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083/4 "2017-04-12T08:28:47Z")

</div>

Hello Board27,

Could you please try following and let me know if this helps you.(Change var's value to your needed line number)

```nohighlight
awk -v DATE=$(date +"%H:%M") -v var=3 'FNR==var{print $0","DATE;next} 1' Input_file

```

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![Board27](https://community.unix.com/letter_avatar/board27/32/6_449c533f586939b6e5f246632a46421f.png) [@Board27](https://community.unix.com/u/Board27)\
**Post date:** [April 12, 2017, 3:30pm UTC](https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083/5 "2017-04-12T15:30:46Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [April 13, 2017, 4:03pm UTC](https://community.unix.com/t/adding-a-timestamp-every-n-row-in-another-column/366083/6 "2017-04-13T16:03:00Z")

</div>

Try also

```nohighlight
awk -v DATE=$(date +"%H:%M") -v var=3 'NR==var {$(NF+1) = DATE} 1' OFS="," file2
167,63.50

167,63.50,22:02

168,63.68

```
