The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
simple for loop ali560045 Shell Programming and Scripting 3 12-17-2007 01:39 AM
Simple BASH script? JayC89 Shell Programming and Scripting 16 10-02-2007 07:23 PM
Bash while loop problem Kweekwom Shell Programming and Scripting 5 07-23-2007 12:49 AM
simple bash script to ftp? satnamx Shell Programming and Scripting 1 04-21-2006 11:18 AM
Simple Bash Script xaphalanx Shell Programming and Scripting 3 12-21-2005 03:54 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-14-2006
kingdbag kingdbag is offline
Registered User
  
 

Join Date: Jun 2006
Location: Las Vegas, NV
Posts: 104
Simple bash for loop problem

I'm just trying to make a script that runs in command line to echo each line in a text file. Everything i found on google is telling me to do it like this but when I run it it just echos removethese.txt and thats it. Anyone know what im doing wrong?

for i in removethese.txt; do echo $i; done

but if I do this

for i in 1 2 3; do echo $i; done

it works...

essentially i need it to run a command for me and not just echo but I was testing it with an echo first and I can't get that to even run.... *sigh*
  #2 (permalink)  
Old 09-14-2006
hnhegde hnhegde is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 22
Try this:

while read aLine
do
printf "\n $aLine"
done < removethese.txt
  #3 (permalink)  
Old 09-14-2006
kingdbag kingdbag is offline
Registered User
  
 

Join Date: Jun 2006
Location: Las Vegas, NV
Posts: 104
sweet, thanks!
  #4 (permalink)  
Old 09-15-2006
inquirer's Avatar
inquirer inquirer is offline
Registered User
  
 

Join Date: Aug 2001
Posts: 79
the reason this did not work:

Code:
for i in removethese.txt; do echo $i; done
is because the for loop does not know what to do with the removethese.txt file. it does not accept files as an input. you can add cat command or similar commands that will read or extract contents of the file then feed them to the for loop. in this case using cat command:

Code:
for i in `cat removethese.txt`; do echo $i; done
thanks
  #5 (permalink)  
Old 09-15-2006
sayonm sayonm is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 30
Talking a dirt code written by me once upone a time........

Code:
n=`wc -l $1 | awk '{print $1}'`
for ((i=1;i<=$n;i++))
do
        echo `head -$i $1 | tail -1`
done
this will also work....preferably, dont use the above code for very huge files(>10mb)
or else u can peacefully use the scripts mentioned earlier
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0