while loop reading 2 files - Unix

This is a discussion on while loop reading 2 files - Unix ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: while loop reading 2 files

  1. 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



  2. Re: while loop reading 2 files

    tony wrote:
    >
    > I got a while loop reading 2 files,


    This is one of the reasons perl was written.

    > 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.


    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.


  3. Re: while loop reading 2 files

    tony wrote:
    > 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


    [...] snip

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


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

    google: expect password

  4. Re: while loop reading 2 files

    In article , "tony"
    wrote:

    > 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


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

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

  5. Re: while loop reading 2 files

    can i use the passwd --stdin to read from a file?
    "Barry Margolin" wrote in message
    news:barmar-0C8823.21285327092005@comcast.dca.giganews.com...
    > In article , "tony"
    > wrote:
    >
    >> 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

    >
    > while read l1 <&3
    > do
    > read l2 <&4
    > echo $l1
    > echo $l2
    > done
    >
    > --
    > Barry Margolin, barmar@alum.mit.edu
    > Arlington, MA
    > *** PLEASE post questions in newsgroups, not directly to me ***




  6. Re: while loop reading 2 files

    tony wrote:
    > can i use the passwd --stdin to read from a file?


    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"

    > "Barry Margolin" wrote in message
    > news:barmar-0C8823.21285327092005@comcast.dca.giganews.com...
    >
    >>In article , "tony"
    >>wrote:
    >>
    >>
    >>>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

    >>
    >>while read l1 <&3
    >>do
    >> read l2 <&4
    >> echo $l1
    >> echo $l2
    >>done
    >>
    >>--
    >>Barry Margolin, barmar@alum.mit.edu
    >>Arlington, MA
    >>*** PLEASE post questions in newsgroups, not directly to me ***

    >
    >
    >


+ Reply to Thread