The UNIX and Linux Forums  

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
redirection problem eric_wong_ch Shell Programming and Scripting 2 06-19-2008 07:14 AM
redirection problem user_prady Shell Programming and Scripting 4 12-10-2007 02:42 AM
Complex Pipeline/Redirection/Regular Expression problem netmaster UNIX for Dummies Questions & Answers 1 11-29-2005 12:55 AM
Redirection Problem vibhor_agarwali UNIX for Dummies Questions & Answers 7 07-14-2005 07:01 AM
facing a problem in redirection vivekshankar UNIX for Dummies Questions & Answers 4 05-23-2005 01:24 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 07-08-2008
mobydick mobydick is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 41
file redirection problem

my querry is

suppose i have duplicate std i/p with FD-3 --exec 0<&3
now redirected std i/p to a file ----exec 0<file1

suppose i am reading the file line by line --while read LINE
cutting some fields and comparing it with a variable and if a match is found
then i have to read new values from the user .

But as std i/p is already redirected
I regain it from FD-3---exec 3<&0
now i read two values ..say read var1;read var2

now i want to again redirect it to the source file and read the next line but the read pointer is going to the top of the file but i want to go to the nextline



can any one tell me how can i preserve the pointer position so that after reviving it , it points to the next line in my file1.
Check the below program if you need an idea

-:my program:-

echo "Enter the friend whose data u want to change ?"
read FRIEND

exec 3<& 0
exec 0<"$DIR/database"

while read LINE
do
candidate=$(echo $LINE | cut -d ' ' -f1)
birthday=$(echo $LINE | cut -d ' ' -f2)
#mobileno=$(echo $LINE | cut -d ' ' -f3)

if [ "$candidate" = "$FRIEND" ] ;then --> match found

exec 0<& 3 -->regaining std i/p
exec 3<&-

echo "Edit your friend's name" --> reading from user
read NAME

echo "Edit your Friend's B'day"
read BIRTHDAY

echo " $NAME $BIRTHDAY">>database1



exec 3<&0 -->again redirecting to the file named database and through the loop reading the next line
exec 0<"$DIR/database"
else

echo " $candidate $birthday">>database1

fi
done
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 10:47 AM.


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