Sting search w/o 'find' or 'du'

Sting search w/o 'find' or 'du'

Post by Bil » Thu, 26 Feb 1998 04:00:00



I'm in a Unix course and I have a question. I need to write a
replacement 'find' command and I've got everything done but one. Given
that I have a list of files in a dir stored in a string array, how do
I search each array element to see if it contains a given substring? I
have to be able to determine if the sub string is contained within the
array element in any fashion (begin, middle, end, etc.)

I would appreciate any help with this. Either post here or email
directly to me. Thanks.

 
 
 

Sting search w/o 'find' or 'du'

Post by Kaz Kylhe » Thu, 26 Feb 1998 04:00:00




>I'm in a Unix course and I have a question. I need to write a
>replacement 'find' command and I've got everything done but one. Given
>that I have a list of files in a dir stored in a string array, how do
>I search each array element to see if it contains a given substring? I
>have to be able to determine if the sub string is contained within the
>array element in any fashion (begin, middle, end, etc.)

I have no clue what language you are working in, but if you are working
in C, then there is a wonderful library function under <string.h>
called ``strstr'' which looks for a substring within a string.

It doesn't do anything fancy like regular expressions, mind you.

You apply it to each element of the array in turn.

 
 
 

Sting search w/o 'find' or 'du'

Post by James Youngma » Thu, 26 Feb 1998 04:00:00


  Bill> I'm in a Unix course and I have a question. I need to write a
  Bill> replacement 'find' command and I've got everything done but
  Bill> one. Given that I have a list of files in a dir stored in a
  Bill> string array, how do I search each array element to see if it
  Bill> contains a given substring? I have to be able to determine if
  Bill> the sub string is contained within the array element in any
  Bill> fashion (begin, middle, end, etc.)

  Bill> I would appreciate any help with this. Either post here or
  Bill> email directly to me. Thanks.

strstr(3).