-1

I want to insert a column the following file using awk. File structure:

1.05228541071 1.04732408695 1.04255736847 1.03783173687 1.03314654421 1.02850114709 ...

I was using the following command to add a column (from 0 days).

awk '{print x+0, $1; x+=73}' file >file_vs_days

And I get the following result for each row:

file_vs_days:

0 1.05228541071 73 1.04732408695 146 1.04255736847 219 1.03783173687 292 1.03314654421 365 1.02850114709 ...

My problem is in the next row (7th), I want it to start at 365 instead of 365 + 73.

For example:

0 1.05228541071
73 1.04732408695
146 1.04255736847
219 1.03783173687
292 1.03314654421
365 1.02850114709
365 x7 
(365+1*73) x8
(365+2*73) x9
(365+3*73) x10
(365+4*73) x11
(365+5*73) x12
...

How can I modify the command to print the values every 6 rows?.

Thanks in advance.

Yro
  • 19
  • 6

2 Answers2

0

This awk one-liner should help you:

awk '{s=73*x++;x=x==6?0:x;print s, $0}' file

If we do a little test:

kent$  awk '{s=73*x++;x=x==6?0:x;print s" - " $0}' <(seq 21) 
0 - 1
73 - 2
146 - 3
219 - 4
292 - 5
365 - 6
0 - 7
73 - 8
146 - 9
219 - 10
292 - 11
365 - 12
0 - 13
73 - 14
146 - 15
219 - 16
292 - 17
365 - 18
0 - 19
73 - 20
146 - 21
Kent
  • 189,393
  • 32
  • 233
  • 301
0

Calculate the first column based on NR (line number):

awk '{print ((NR-1)%6*73), $0}' file
oguz ismail
  • 1
  • 16
  • 47
  • 69