LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 03-18-2009, 06:47 AM   #1
Proxx
LQ Newbie
 
Registered: Sep 2007
Location: Holland
Posts: 20

Rep: Reputation: 0
for loop in unix


Hello im sorry to bother you with this. but i have a question about the for loop

but i cant figure it out.

Here it is!

i have a file with a number on every line

i want to run a command on every line separately: example

command (number of first line of file)
command (number of the second line of file)

i know i can do this with the for but its driving me nuts.



maybe somebody can give me an hint of example ?



Thanx in advance
 
Old 03-18-2009, 06:51 AM   #2
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
Does this help:
Code:
~$ echo -e "1\n2\n3\n" > test-file
~$ for i in $( < test-file); do echo $i; done
1
2
3
~$
 
Old 03-18-2009, 07:04 AM   #3
Proxx
LQ Newbie
 
Registered: Sep 2007
Location: Holland
Posts: 20

Original Poster
Rep: Reputation: 0
Thank you for the quick reply. that is just what i needed

sorry to bother you for this simple thing

MOD: please close this topic

Thanx again

Last edited by Proxx; 03-18-2009 at 08:39 AM.
 
Old 03-18-2009, 08:46 AM   #4
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
No worries! For future reference, this guide has lots of examples for all the different aspects of bash syntax:
http://tldp.org/LDP/abs/html/

The bash manpage is also useful, but only after you're already fairly familiar with bash.
 
  


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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 04:49 PM
bash loop within a loop for mysql ops br8kwall Programming 10 04-30-2008 04:50 AM
converting shell while loop to for loop farkus888 Programming 8 09-12-2007 03:30 AM
LXer: Speaking UNIX, Part 4: Setting and managing permissions on UNIX LXer Syndicated Linux News 0 10-21-2006 02:54 AM
for loop only works properly on first loop symo0009 Programming 1 12-25-2005 06:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:03 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