Kevin,

Thank you very much! I really appreciate it.

I like your "find" approach, it's simple and easy to understand.

I'll also try to understand your perl approach, when I got time to start learning it. (Hopefully it won't be un-fulfilled forever)

I have one more question:

Is it possible to number the extracted string2?

Say, the output file contains the following list of extracted string2:

st
region
local

Any idea about what command to use to number the list to make it look like below:

1 st
2 region
3 local

Again, thank you for your help and time!

Zhao

Kevin D. Clark wrote:
Zhao Peng writes:

I'm back, with another "extract string" question. //grin


find FOLDERNAME -name \*sas7bdat -print | sed 's/.*\///' | cut -d _ -f 2 | sort -u 
> somefile.txt

or

perl -MFile::Find -e 'find(sub{$string2 = (split /_/)[2]; $seen{$string2}++; }, @ARGV); 
map { print "$_\n"; } keys(%seen)' FOLDERNAME

(which looks more readable as:

  perl -MFile::Find -e 'find(sub{ $string2 = (split /_/)[2];
                                  $seen{$string2}++;
                                 }, @ARGV);
map { print "$_\n"; } keys(%seen)' \
          FOLDERNAME > somefile.txt

)

Either of which solves the problem that you describe.  Actually, they
solve more than the problem that you describe, since it wasn't
apparent to me if you had any subdirectories here, but this is solved too)

(substitute FOLDERNAME with your directory's name)


Honestly, the first solution I present is the way I would have solved
this problem myself.  Very fast this way.

Regards,

--kevin

_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss

Reply via email to