Adding a timestamp every N row in another column

Hi,
i have a raw output file like this

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

date +"%H:%M"

how can i do it with one single command ?

Thank you !!

Hello Board27,

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

 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

1 Like

it comes :

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!

Hello Board27,

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

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

Thanks,
R. Singh

1 Like

thanks

Try also

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