LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   list directory names feed to next command (https://www.linuxquestions.org/questions/linux-newbie-8/list-directory-names-feed-to-next-command-4175556109/)

SuKHI 10-14-2015 04:44 AM

list directory names feed to next command
 
hi all,

need help for writing a script.
i have a bpm directory which has list of nodes. which are folder names.
i want to list these names, save somewhere or directly pass the names one by one to next command and get the command out save in some file.

i tried using ls, cut, grep etc....not successfully.
any body mastered with awk or sed kindly can help me.

e.g., Dir A
having B,C,D,E etc.
Get the B,C,D,E and pass to command one by one. n save the output to other file for further manipulations.

Thanks...

berndbausch 10-14-2015 05:47 AM

What do you mean by "pass to the command"?

Perhaps this:
Code:

cd DirA
for file in *
do yourcommand $file
done > outputfile


zhjim 10-14-2015 06:05 AM

Could use find for this. Use the -exec function

Quote:

# this ones optional if you search for only named files|directories
#name="-iname name/of/file/*"
find /path/to/dir $name -exec cat \{\} \;
cat here is the command to execute. The {} gets expanded for every file found. \; ends the command to be executed. You have to escape {} as well as ; else it gets interpreted by the shell. Check the man page for further examples

SuKHI 10-16-2015 12:31 AM

here is the situation:

Directory A contains few directories.
I want to get the name in a variable.
Then there will put a for loop
which will take those names one buy one n next command will be having the values of that variable which will generate output of memory management using that variable name.
then I will store the output in file...

I can do ls in a loop and store the name of directories...
then in do part will put the other command and pass the listed directories name one by one to command n keep storing the output to a file.

but somehow i think somewhere i m wrong n it won't work...

P.S i'm a newbie...
help plz

chrism01 10-16-2015 01:22 AM

Try to actually write some code - we're here to help, not do it for you.
You've got some good advice above; have a go at it and see what you can achieve.
If you do this, you'll get lots more help if you need it.


All times are GMT -5. The time now is 09:28 AM.