extract string from filename

Ben Scott dragonhawk at gmail.com
Fri Jan 13 12:19:01 EST 2006


On 1/13/06, Zhao Peng <greenmt at gmail.com> wrote:
> Is it possible to number the extracted string2?

find -name \*sas7bdat -printf '%f\n' | cut -d _ -f 2 | sort | uniq | cat -n

  Run that pipeline in the directory you are interested in.

  The find(1) command finds files, based on their name or other
filesystem attributes.

  The "-name \*sas7bdat" part finds files with file names which match
the pattern.  There backslash escapes the star, to keep the shell from
trying to interpret it, so find gets the star instead.

  The "-printf '%f\n'" part has find output just the file name, not the path.

  cut(1) is used to split input strings, as you know.  "-d _" splits
into fields, based on underscores.  "-f 2" outputs the second field
only, one per line.

  sort(1) sorts, and uniq(1) eliminates duplicate lines.

  "cat -n" numbers the output.

-- Ben "Pay attention, there's gonna be a quiz next week" Scott



More information about the gnhlug-discuss mailing list