Home > Back-end >  I have a file in Unix with data set as below, i want to generate more data like this but no duplicat
I have a file in Unix with data set as below, i want to generate more data like this but no duplicat

Time:11-23

I want to generate more data based on some sample data i already have in a file stored in Unix location. looking for a unix shell code.

ID,FN,LN,Gender
1,John,hopkins,M
2,Andrew,Singh,M
3,Ram,Lakshman,M
4,ABC,DEF,F
5,Virendra,Sehwag,F
6,Sachin,Tendulkar,F

CodePudding user response:

You could use awk to read the existing data into an array and then keep printing it over and over with new IDs:

awk -F, -v OFS=, -v n=100 '
  BEGIN {
    l = 0;
  }
  /^[0-9]/ {
    a[l] = $2","$3","$4;
    l  ;
  }
  { print }
  END {
    for ( i = l; i <= n; i   ) {
      printf "%d,%s\n", i, a[i%l];
    }
  }
'

n is the number of IDs you want (existing IDs generated).

  • Related