I have a file in Unix with data set as below, i want to generate more data like this but no duplicates. Looking for a unix shell code. Below is sample

I have a file in Unix with data set as below, i want to generate more data like this but no duplicates. Looking for a unix shell code. Below is sample

Problem Description:

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

Solution – 1

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,%sn", i, a[i%l];
    }
  }
'

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

Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject