Tuesday, February 27, 2007

Extracting top level dir names


A very simple post! This is for those who "just" started awk, others can skip :-)

Suppose dir.names contain the following data
$ cat dir.names
/usr/local/test
/usr/bin/test
/opt/ivoli/dat
/opt/lib/test
/tmp/files/test
/tmp/local/test

Purpose is to extract the top level directory names i.e.
/opt
/tmp
/usr

$ awk -F "/" '{print "/"$2}' dir.names | sort | uniq

No comments:

© Jadu Saikia www.UNIXCL.com