1

I am trying to write a shell script to find value stored after a repetitive word in a big file with millions of lines using for loop. After the finding the repetitive word how i make script to start searching after the present line in file so that when the loop iterates it doesn't start searching from beginning of the file.

Simply how to find the current line in a file and how to start search from that line when loop re-iterates, instead of start searching from the beginning.

And how many parallel crones can i run is there any limit or just we need run depending on our CPU and RAM utilization.

  • 1
    There is nothing like a current line in an unopened file. The cursor comes from the file functions in the standard libraries. It would be possible to keep a reference to what you consider to be the current line in different ways, but so far it seems this would be better addressed on http://unix.stackexchange.com – Julie Pelletier Jun 12 '16 at 16:44
  • 2
    Shell is probably the wrong tool for this job. Consider python or perl. – user9517 Jun 12 '16 at 16:54

1 Answers1

0

This is what I use to find out in a log file if the program started successfully.

To find the current file size you can use:

current_pos=$(stat -c "%s" file)

And then you use the output of

tail -c +$current_pos file

to start searching from remembered position.

But then it is possible that when you read the file size (and also when you do the search) the last line to be incomplete. This depends on the program which writes the file.

Laurentiu Roescu
  • 2,266
  • 17
  • 17