![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|