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