Results 1 to 10 of 10

Thread: loop with input file?

Hybrid View

  1. #1
    Associate
    Join Date
    Mar 2006
    Posts
    21

    loop with input file?

    I have a file with a list of user names, such as

    john
    jan
    test
    dennis
    etc...

    I want to read in the account name, change the password parameters, then move on to the next name in the list.

    A loop of course, but I can't figure out how to specify the input file, and how to read one name at a time.

    Any ideas would be appreciated.

  2. #2
    Advisor Outlaw's Avatar
    Join Date
    May 2001
    Location
    Clifton Park, NY
    Posts
    630
    Quickly, since its almost miller time:

    Assuming user.txt

    Code:
    [wayne@UW-GOODRICHWE ~]$ for i in `cat user.txt`; do echo $i.user; done
    john.user
    jan.user
    test.user
    dennis.user
    Code:
    #!/bin/bash
    #
    for i in `cat user.txt`
    do
        echo "$i.luser"
    done
    That just shows the mechanics of the for loop. You want to actually perform an action on the value of $i in a bash script

  3. #3
    Associate
    Join Date
    Mar 2006
    Posts
    21
    Next I had to learn that ` does not equal '. Made an amazing difference! Thanks again.

  4. #4

    basic linux loop

    Hi Sabre,

    I was wondering if you would mind helping me with a similar problem??
    I have saved a file ...

    [lg45@dev64-mgmt ~]$ cat table.txt

    Angiogenin 10 25793633 25815393
    Alpha-actinin 28 7893500 7941168
    The example above (for i in `cat user.txt`; do echo $i; done) does not give me the same result and i am unsure why. instead i get the following:

    [lg45@dev64-mgmt ~]$ for in in `cat table.txt`; do echo $i; done
    table.txt
    table.txt
    table.txt
    table.txt
    table.txt
    table.txt
    table.txt
    table.txt
    I am trying to write a loop that will pull out column 2 in every line of table.txt, and allow me to modify it
    Any suggestions would be appreciated

    Thanks,
    Lel

  5. #5
    Sorry - message is for outlaw...

  6. #6
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    Code:
    #  for in in `cat table.txt`; do echo $i; done
    It should be
    Code:
    # for i in `cat table.txt`; do echo $i; done
    the misspelling makes a huge difference.
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  7. #7
    Hi redhead - sorry that typo was fixed up but still does not give me the answer im looking for. It gives all the information in one column, when i require a loop through column 2.

  8. #8
    For more information, i have a file with 3 columns. ie
    #Animal Start Stop
    Dog 4 5
    Cat 5 6
    Owl 8 9
    And i want to loop through file #2 and pull out all the lines with a start stop the same as file #1 above
    ie the bolded lines

    #Animal Start stop
    monkey 1 2
    monkey 2 3
    monkey 3 4
    monkey 4 4
    monkey 5 6
    monkey 6 8
    monkey 7 9

  9. #9
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    Then you need to do it in some perl-scripting, bash script wouldn't be the tool for the job, when you need to compare several flags.

    I'm guessing here, you need to filter file #2 and identify "Dog" there with a start=4 and filter any line between this and when reaching line "Dog" with a stop=5, am I right ?
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

  10. #10
    Thanks for the reply redhead, Thats right thats exactly what i am trying to do!!!
    So i have written the following to define start and stop...

    [lg45@dev64-mgmt ~]$ for i in `seq 1 7`; do start=`head -$i regions.txt | awk '{print $3}'`; done
    [lg45@dev64-mgmt ~]$ start=`head -$i regions.txt | awk '{print $3}'`
    [lg45@dev64-mgmt ~]$ echo $start
    25293633 7393500 10578865 25293623 122206254 26797134 41906484
    [lg45@dev64-mgmt ~]$ stop=`head -$i regions.txt | awk '{print $4}'`
    [lg45@dev64-mgmt ~]$ echo $stop
    26315393 8441168 11592811 26315362 123286509 27802564 42911309
    [lg45@dev64-mgmt ~]$
    Now i am trying to loop through file #2 (format as above) with a statement such as this....

    awk '{ if($3>$start'$$3<'$stop')print$0}'
    But i think there is something wrong with the syntax and i am having trouble figuring out how to write the loop
    Does that make sense??

Similar Threads

  1. restarting loop
    By tolentinopol in forum Windows - General Topics
    Replies: 1
    Last Post: 01-10-2007, 10:07 AM
  2. rebooting loop
    By j9sheldon in forum Windows - General Topics
    Replies: 1
    Last Post: 10-24-2006, 05:38 AM
  3. if/then Loop question
    By vwgtiturbo in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 06-21-2006, 04:40 PM
  4. compile stuck in loop?
    By cj171 in forum Linux - General Topics
    Replies: 8
    Last Post: 05-08-2004, 10:10 PM
  5. File management & input/output stuff
    By steveharman1 in forum Linux - General Topics
    Replies: 1
    Last Post: 07-03-2002, 02:29 PM

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
  •