Professional Web Applications Themes

while loop reading 2 files - Linux / Unix Administration

I got a while loop reading 2 files, both files has one column. file one have a list of login names file two has a list of passwords I want to run a while do script to read file one and set the password as it shows on file 2 exec 3< users exec 4< pass while read l1 <&3 ; read l2 <&4 do echo $l1 echo $l2 done I need to modify this to do what I need it to do. Please help...

  1. #1

    Default while loop reading 2 files

    I got a while loop reading 2 files,

    both files has one column.

    file one have a list of login names
    file two has a list of passwords


    I want to run a while do script to read file one and set the password as it
    shows on file 2


    exec 3< users
    exec 4< pass

    while read l1 <&3 ; read l2 <&4
    do
    echo $l1
    echo $l2
    done

    I need to modify this to do what I need it to do. Please help


    tony Guest

  2. #2

    Default Re: while loop reading 2 files

    tony wrote: 

    This is one of the reasons perl was written.
     

    It would be so cool if shells could do this, but perl is
    great at it.

    Alternately, if the files are small enough, use a pair of
    loops and arrays. Something like:

    count=1
    cat user | while read i ; do
    USER[${count}]=${i}
    count=`expr ${count} + 1`
    done
    count=1
    cat pass | while read i ; do
    PASS[${count}]=${i}
    count=`expr $count} + 1`
    done

    I usually have to mess with the exact syntax a couple of
    times when I try to use shell variables since I only use
    them every few years. Perl does effectively replace any
    need for them.

    Doug Guest

  3. #3

    Default Re: while loop reading 2 files

    tony wrote: 

    [...] snip
     

    Won't work, you can't redirect passwd that way.

    google: expect password
    base60 Guest

  4. #4

    Default Re: while loop reading 2 files

    In article <dhce6j$mjc$Stanford.EDU>, "tony" <com>
    wrote:
     

    while read l1 <&3
    do
    read l2 <&4
    echo $l1
    echo $l2
    done

    --
    Barry Margolin, mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    Barry Guest

  5. #5

    Default Re: while loop reading 2 files

    can i use the passwd --stdin to read from a file?
    "Barry Margolin" <mit.edu> wrote in message
    news:dca.giganews.com... 
    >
    > while read l1 <&3
    > do
    > read l2 <&4
    > echo $l1
    > echo $l2
    > done
    >
    > --
    > Barry Margolin, mit.edu
    > Arlington, MA
    > *** PLEASE post questions in newsgroups, not directly to me ***[/ref]


    tony Guest

  6. #6

    Default Re: while loop reading 2 files

    tony wrote: 

    Again, "passwd" will *not* accept redirection.

    If you want to script this sort of thing, your best bet
    is to used "expect"

    Google: "expect passwd unix"
     
    >>
    >>while read l1 <&3
    >>do
    >> read l2 <&4
    >> echo $l1
    >> echo $l2
    >>done
    >>
    >>--
    >>Barry Margolin, mit.edu
    >>Arlington, MA
    >>*** PLEASE post questions in newsgroups, not directly to me ***[/ref]
    >
    >
    >[/ref]
    base60 Guest

Similar Threads

  1. CS3 not reading CS2 files
    By Marco_Crisari@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 4
    Last Post: July 14th, 08:04 PM
  2. Reading files into PHP
    By Marco in forum PHP Development
    Replies: 5
    Last Post: April 7th, 11:27 PM
  3. Reading old EPS files
    By Len Enry in forum Adobe Illustrator Windows
    Replies: 9
    Last Post: April 21st, 02:42 PM
  4. Reading files
    By mgoland@optonline.net in forum PERL Beginners
    Replies: 8
    Last Post: December 3rd, 10:37 PM
  5. Reading csv files
    By ali_bongo_ webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: October 30th, 10:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139