LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-14-2015, 05:44 AM   #1
SuKHI
LQ Newbie
 
Registered: Dec 2007
Posts: 14

Rep: Reputation: 0
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...
 
Old 10-14-2015, 06:47 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora
Posts: 1,688

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
What do you mean by "pass to the command"?

Perhaps this:
Code:
cd DirA
for file in *
do yourcommand $file
done > outputfile
 
Old 10-14-2015, 07:05 AM   #3
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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

Last edited by zhjim; 10-14-2015 at 07:07 AM.
 
Old 10-16-2015, 01:31 AM   #4
SuKHI
LQ Newbie
 
Registered: Dec 2007
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 10-16-2015, 02:22 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,260

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
List file names in a directory WITHOUT the path dexus Linux - Newbie 16 11-09-2016 08:58 PM
How to list and sort files in some directory by the names on Linux/Win in C ? Xeratul Programming 9 10-06-2015 04:48 PM
[SOLVED] List files/directory names without directory contents? littlebigman Linux - Software 2 05-03-2011 05:42 AM
Finger command to list all the user names narainhere Programming 3 09-03-2007 04:56 AM


All times are GMT -5. The time now is 04:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration