LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-30-2007, 03:47 PM   #1
christianunix
Member
 
Registered: Oct 2007
Posts: 40

Rep: Reputation: 15
YASQ Yet Another Simple Question regarding scripting


my pwd contains files and directories named nick and emptydr

Code:
ls -l|grep dwrx|cut -d' ' -f9
returns the name of the directories in my pwd.

let's say I save the result of the above command into a file named listing.

then the file listing will contain the following"

nick
emptydr

and now, I would like to write my script so my script uses each line in the file named listing as the input of the file. How can I do that?

thanks
 
Old 10-31-2007, 09:16 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I think you want the "read" command.

For example, this:
read line1 < filename
reads the first line of "filename" into the variable "line1"

You could do it in a loop in which each invocation of "read" puts a line into an array, indexing the array as you go.

I recommend going to tldp.org and getting the Advanced Bash Scripting Guide. Unless you have a personal forest, don't print it!! I just use it for searches.
 
Old 10-31-2007, 10:29 AM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
Code:
ls -l|grep dwrx
Better to use this:
Code:
ls -l| grep ^d
^d means lines beginning with d

and then using result (here I simply use echo to print each line):

Code:
cat file  | while read i; do echo $i; done
 
  


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
simple scripting question jerf Linux - Newbie 4 09-19-2007 03:12 AM
simple question regarding shell scripting branche_dude Linux - Newbie 8 07-21-2006 02:35 AM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 01:44 PM
simple scripting question wedgeworth Programming 6 02-04-2004 10:30 AM
YASQ - yet another samba question itsjustme Linux - Networking 9 10-07-2003 04:45 PM


All times are GMT -5. The time now is 10:17 AM.

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