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
for loop in unix deep_kol Shell Programming and Scripting 1 04-29-2008 10:39 AM
Unix-Sql Loop error manu_byc Shell Programming and Scripting 3 02-05-2007 09:40 AM
Loop through file and write out lines to file(s) Jtrinh Shell Programming and Scripting 7 07-05-2005 03:06 AM
Please help with UNIX while loop... gerard1 Shell Programming and Scripting 1 02-01-2005 12:39 PM
timing a loop in unix. wolkott Shell Programming and Scripting 1 02-04-2003 02:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-06-2007
dkranes dkranes is offline
Registered User
  
 

Join Date: Apr 2007
Location: Hudson Valley Region in New York
Posts: 43
Unix Loop from a file

Hello, I would like to be able to read a file that contains a list of database tables and loop through each entry and delete rows in the database for that entry. I thought you could do this with the cat command. I can not find examples any where. Could someone kindly provide a looping mechanism to read a file and do this? Thank you.


David
  #2 (permalink)  
Old 04-06-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
David,
As we know, there are several ways to skin a cat.
Here is one form of looping using shell script:
while read EachRecord
do
echo "EachRecord = "$EachRecord
done < input_file
  #3 (permalink)  
Old 04-06-2007
dkranes dkranes is offline
Registered User
  
 

Join Date: Apr 2007
Location: Hudson Valley Region in New York
Posts: 43
Sorry but I am new to shell scripting. Could you kindly explain what each line is doing. Where would I reference my file name as the input. Sorry for my ignorance. Thank you.

David
  #4 (permalink)  
Old 04-06-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Here it goes:

while read EachRecord
The above line makes the loop happens reading each record from
the input file and assigning it to the variable "EachRecord".

do
The above line specifies the beginning of a block of statements
in this case, inside of the "while" loop.

echo "EachRecord = "$EachRecord
The "echo" statement displays on standard output -- screen.
In this case it is displaying a string "EachRecord = " and the content
of the variable "EachRecord".

done < input_file
The "done" is the end of block.
The "input_file" is to be replaced by your input file with your data.
  #5 (permalink)  
Old 04-06-2007
dkranes dkranes is offline
Registered User
  
 

Join Date: Apr 2007
Location: Hudson Valley Region in New York
Posts: 43
Great! Thank you very much for you patients and help.

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 12:50 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