DBAsupport.com Forums - Powered by vBulletin
Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: How to read a file in UNIX

  1. #11
    Join Date
    Sep 2001
    Location
    Düsseldorf, Germany.
    Posts
    588

    How to read a file in UNIX

    Still I need help.. :-((

    Now scrit looks like
    ----------------------
    #/bin/sh
    filename='/opt/oracle/sameerd/sam/sam.txt'
    for LINE in `cat $filename`
    do
    ID=`echo $LINE | cut -d'|' -f1`
    FIRSTNAME=`echo $LINE | cut -d'|' -f2`
    LASTNAME=`echo $LINE | cut -d'|' -f3`

    echo "Id is " $ID
    done
    -----------------------

    My line is

    10 | J OHN | MILLER
    20 | MARK | BRUNCE

    And the output is...

    ----------------------
    Id is 10
    Id is
    Id is J
    Id is OHN
    Id is
    Id is MILLER
    Id is 20
    Id is
    Id is MARK
    Id is
    Id is BRUNCE
    ----------------------

    When I have said echo ONLY ID.. why the output is displaed for each element?

    Thanks

    Sameer




  2. #12
    Join Date
    Feb 2001
    Location
    Paris, France
    Posts
    809
    ok, instead of using :

    for LINE in $(cat file)
    do
    ...

    use :

    cat file | while read LINE
    do
    ...

  3. #13
    Join Date
    Sep 2001
    Location
    Düsseldorf, Germany.
    Posts
    588

    Talking How to read a file in UNIX

    Hey...

    THANKS A LOT

    I am sorry.. But I really asked YOU THOUSANDS of silly questions...

    But I am very new to shell scripts..

    Thanks once again

    Sameer


Posting Permissions

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


Click Here to Expand Forum to Full Width