Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8029885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:34:29+00:00 2026-06-05T00:34:29+00:00

Possible Duplicate: Need help in bash script and awk command I need a bash

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:34:32+00:00Added an answer on June 5, 2026 at 12:34 am

    This may get you part of the way there…

    find /earth | sed -e 's/\// /' | awk '{ print "planet = " $1 "\ncategory = " $2 "\nsubcat = " $3 "\nname = " $4}'
    

    I’ll break it apart so others may improve / modify

    find /earth
    

    find simply dumps a listing of all the contents of the /earth directory

    sed -e 's/\// /'
    

    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.

    awk '{ print .... }'
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Need help in structuring things in XML file have a structure like
Possible Duplicate: Detecting closest or parent div I need some help about finding elements
Possible Duplicate: When do I need to specify the JavaScript protocol? for example <body
Possible Duplicate: Why was the switch statement designed to need a break? I have
Possible Duplicate: Appending files to a zip file with Java I have a zip
Possible Duplicate: Event handlers inside a Javascript loop - need a closure? I have
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
Possible Duplicate: Can any one help me, to create .apk file for google android
Possible Duplicate: need help with some stored procedure plz ERROR:- A SELECT statement that
Possible Duplicate: Determine framework (CLR) version of assembly I have a library/DLL file which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.