Results 1 to 6 of 6

Thread: I have two and need to get data from that using loop

  1. #1
    Join Date
    Sep 2008
    Beans
    70

    I have two and need to get data from that using loop

    Hi all i have two contain some data
    like file1

    123
    345
    345

    File2
    abc
    xyz


    I want to pass each value from both file to a command in a loop.I try cat with loop but not working because i have two file.And need to pass data from two file one by one to command.I am using bash



    like command is this

    ls $file1 $file2
    can any one guid me

  2. #2
    Join Date
    Mar 2005
    Location
    Alba
    Beans
    73
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: I have two and need to get data from that using loop

    Hello,

    I'm not sure if I understand what exactly you are asking for but try this...

    Code:
    paste file1 file2
    and see

    Code:
    man paste
    for more information.

    -weresheep

  3. #3
    Join Date
    Sep 2008
    Beans
    70

    Re: I have two and need to get data from that using loop

    Hi thanks for your quick answer but i know about paste

    look my little example


    file1

    abc
    bcd
    yhx

    file2
    45
    67
    78

    for in file1 file2

    file1=get first value from file1
    file2=get first value from file2
    and soo on ...................
    ls $file1 $file2
    done
    got my point

  4. #4
    Join Date
    Mar 2005
    Location
    Alba
    Beans
    73
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: I have two and need to get data from that using loop

    Okay,

    How about...

    Code:
    paste file1 file2 | while read LINE ; do
      f1=$(echo $LINE | awk '{print $1}')
      f2=$(echo $LINE | awk '{print $2}')
    
      echo "f1 is $f1 and f2 is $f2"
    
      # Do stuff with $f1 and $f2 here
    
    done
    -weresheep

  5. #5
    Join Date
    Sep 2008
    Beans
    70

    Re: I have two and need to get data from that using loop

    yes thanks

  6. #6
    Join Date
    Sep 2006
    Beans
    2,914

    Re: I have two and need to get data from that using loop

    Quote Originally Posted by weresheep View Post
    Okay,

    How about...

    Code:
    paste file1 file2 | while read LINE ; do
      f1=$(echo $LINE | awk '{print $1}')
      f2=$(echo $LINE | awk '{print $2}')
    
      echo "f1 is $f1 and f2 is $f2"
    
      # Do stuff with $f1 and $f2 here
    
    done
    -weresheep
    no need awk..
    Code:
    # paste file1 file2 | while read a b
    > do
    > echo $a $b
    > done

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
  •