extract string from filename
Zhao Peng
greenmt at gmail.com
Thu Jan 12 19:41:01 EST 2006
Hi all,
I'm back, with another "extract string" question. //grin
I have almost 1k small files within one folder. The only pattern of the
file names is:
string1_string2_string3_string4.sas7bdat
Note:
1, string2 often repeat itself across each file name
For example:
abc_st_nh_num.sas7bdat
abc_st_vt_num.sas7bdat
abc_st_ma_num.sas7bdat
abcd_region_NewEngland_num.sas7bdat
abcd_region_South_num.sas7bdat
2, All 4 strings contain no underscores.
3, 4 strings are separated by 3 underscores (as you can see)
4, The length of all 4 strings are not fixed.
My goal is to :
1, extract string2 from each file name
2, then sort them and keep only unique ones
3, then output them to a .txt file. (one unique string2 per line)
I tried to use "cut" commands, but can't even figure out how to use the
filenames as input. Anyone care to offer me a hint?
I also downloaded an e-book called "Learning Perl" (OReilly,
4th.Edition), and had a quick look thru its Contents of Table, but did
not find any chapter which looks likely addressing any issue related to
my question.
Thank you very much!
Zhao
More information about the gnhlug-discuss
mailing list