Home > Net >  using shell script ,replicate a record from a file 1000 times or n times by incrementing few records
using shell script ,replicate a record from a file 1000 times or n times by incrementing few records

Time:11-28

I have a record in a file named abc.txt as below:

ID, date, timestamp, count, idcount, unit, code, Pcode, ccode, bid, vcode

12345432,10-11-2011,11:11:12.555,0,0,XVC_AS,12,14,19,123454323,qweds

I want to write a unix shell code to generate more no. of record by just incrementing the column ID,Pcode and ccode and remaining column as it is.

Example of output file

12345432,10-11-2011,11:11:12.555,0,0,XVC_AS,12,14,19,123454323,qweds

12345433,10-11-2011,11:11:12.555,0,0,XVC_AS,12,15,20,123454323,qweds

12345434,10-11-2011,11:11:12.555,0,0,XVC_AS,12,16,21,123454323,qweds

12345435,10-11-2011,11:11:12.555,0,0,XVC_AS,12,17,22,123454323,qweds

12345436,10-11-2011,11:11:12.555,0,0,XVC_AS,12,18,23,123454323,qweds

12345437,10-11-2011,11:11:12.555,0,0,XVC_AS,12,19,24,123454323,qweds
.
.
.
.
1000 times or n times

i tried duplicating the file and few awk commands, but unable to understand how to increment the IDs and other column

CodePudding user response:

To increment the values of the last record provided N times, you can use

awk -v{O,}FS=, -vN=1000 '{print} END {for(i=0;i<N;i  ){$1  ;$8  ;$9  ;print}}' file
  • Related