nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Need Help reading files

This is a discussion on Need Help reading files within the Shell scripting forums, part of the Development/Scripting category; Hi all, I am new to unix shell scripting. I want to write a bash shell script. I have a ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-22-2005, 12:17 AM
Junior Member
 
Join Date: Jul 2005
Posts: 1
mustang
Default Need Help reading files

Hi all,

I am new to unix shell scripting. I want to write a bash shell script.

I have a text file say "sample.txt" which has entries seperated by space or commas.

table_name,schema_name,no_of_days_to_delete_data
table1,sam,25
table2,jim,30
table3,kim,15

I want to read line by line the above sample.txt file in my shell script and pass these 3 parameters in one line to some oracle procedure while looping it..

pseudocode as follow:
-------------------------
open sample.txt file
while not end of file
read one line
pass the values to some oracle procedure..
end while loop
close file.


How do I achieve the above functionality in shell script?

New Beginner..please help me.

Note : OS is Linux Platform.
I need the 3 parameters to be passed to oracle procedure to delete some data which might take a while finishing the procedure...then I will read the next line and pass these parameters again to oracle and so on....

Regards
Mustang
Reply With Quote
  #2 (permalink)  
Old 07-22-2005, 01:49 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Any distro with shell
Posts: 879
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Following script logic will store line in $line and 3 fields in $f1, $f2, $f3
Code:
#!/bin/bash
filename="data.txt"
# line stores the one single line from $filename
while read line
  do
     f1="$(echo $line| cut -d, -f1)"
     f2="$(echo $line| cut -d, -f2)"
     f3="$(echo $line| cut -d, -f3)"
     # use f1 f2 f3 as parameter to  pass the values to some oracle procedure...
     # /path/to/oracle-client $f1 $f2 $f3
done < $filename
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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


Similar Threads

Thread Thread Starter Forum Replies Last Post
Shell script for automatic conversion of files in tar files kasimani Shell scripting 2 02-08-2007 03:45 PM
Re-reading the partition table failed with error 16: Device chiku Linux software 1 12-07-2006 08:45 PM


All times are GMT +5.5. The time now is 05:05 PM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35