Possible Duplicate:
Need help in bash script and awk command
I need a bash script to print directory names and file names recursively . For example: i have a directory structure like:
/earth/plants/flowers/rose/rose.jpg.
/earth/plant/fruits/apple/apple.jpg.
/earth/animals/carni/lions.jpg
/earth/animals/herbi/omni/dog.jpg
Now I need to list this files and folders like this — I mean my O/P should be,
planet=earth
category=animal (plant)
sub cat = carni
name = lion.jpg.
In some places I have additional directories also.like /earth/animals/carni/jungle/lions.jpg.
Then I need to display that lions.jpg file size also.
This may get you part of the way there…
I’ll break it apart so others may improve / modify
find simply dumps a listing of all the contents of the /earth directory
I’m replaced all the forward slashes with the space character so I can easily break apart the words. I could do without this step by telling awk to use the forward slash as the delimiter, but this may (or may not) by useful to future revision, so I leave it.
I’m telling awk to print the input it’s given with the various categories listed in the question. $1 means the first token. $2 the second token and so on. awk understands lines breaks as well “\n”.
I’m not sure what to do if you have several subcategories, however this should get you close.