#!/usr/bin/octave -qf % Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) % % This work is licensed under the Creative Commons Attribution-NonCommercial- % ShareAlike License. To view a copy of this license, visit % http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to % Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, % 94105, USA. if length(argv) != 2, fprintf(stderr, "Usage:\n\t%s (search value) (file with list of values)\n", program_name); exit(-1); endif value = str2num(argv{1}); file_name = argv{2}; if (fh = fopen(file_name, "r")) == -1, fprintf(stderr, "Error: can't open %s\n", file_name); exit(-1); endif % read in the entries entries = fscanf(fh, "%f\n"); fclose(fh); % find all matching entries matching_indices = find(entries==value); % check to see if there are any matching entries if length(matching_indices) == 0, fprintf(stderr, "Search value not found.\n"); exit(-1); endif % display line numbers for the matching entries for index=matching_indices, printf("found match on line: %d\n", (index+1)); end