Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am straggling to write a bash script code for markov word chain of order 3. I have put some examples and some text files

I am straggling to write a bash script code for markov word chain of order 3. I have put some examples and some text files how it should look like. If there you could help me how to implement please that would be so helpful. I have added the shuffle.c file image text in transcribed

image text in transcribed

// // shuffle.c // Filter that reads evey lines from stdin (or a specified file), // shuffles them randomly, and outputs the shuffled lines to stdout. // This is a partial replacement for the 'shuf' command provided // with most Linux installations. // Author: W. Cochran wcochran@wsu.edu // #include  #include  #include  // // Seed stdlib's random() with a random // seed using kernel urandom device. // void seedRandom(void) { FILE *f; if ((f = fopen("/dev/urandom", "rb")) == NULL) { perror("/dev/urandom"); exit(-1); } unsigned int seed; fread(&seed, sizeof(seed), 1, f); fclose(f); srandom(seed); } // // FisherYates shuffle using stdlib's random() // https://en.wikipedia.org/wiki/FisherYates_shuffle#Potential_sources_of_bias // Not really doing this exactly right, see // https://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful // void shuffle(int numLines, char *lines[]) { for (int i = 0; i = 2) { f = fopen(argv[1], "rb"); if (f == NULL) { perror(argv[1]); exit(1); } } // // Buffer each input line into (dynamically sized) array. // Caveat: Assume lines are less than 200 chars long (I'm too // lazy to do this right). // int capacity = 10; int numLines = 0; char **lines = (char **) malloc(capacity * sizeof(char *)); char buf[200]; while (fgets(buf, sizeof(buf), f) != NULL) { if (numLines >= capacity) { capacity *= 2; lines = realloc(lines, capacity * sizeof(char *)); } lines[numLines++] = strdup(buf); } fclose(f); // // Seed random number generator used by shuffle. // seedRandom(); // // Shuffle lines. // shuffle(numLines, lines); // // Echo shuffled lines to stdout. // for (int i = 0; i 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions