New here? Register and read our Community Rules. Accounts are approved by hand.

bash loop help

exussumexussum Member
edited August 2012 in General

Im Trying to loop though a file line by line and run some commands based on input.
Where im struggling is

while read line;do
echo $line;
done < item.txt

misses the first line each time. Is there something wrong with the command ?

Comments

  • AsadAsad Member
    edited August 2012

    @exussum That works fine for me and reads the first line.

    That's exactly how it's supposed to be too.

    while read LINE ; do
    echo $LINE
    done < my.file

  • exussum@exussumuk:~$ cat item.txt
    13358
    13359exussum@exussumuk:~$ bash test.sh
    13358
    

    is what i get. cat shows item.txt having 2 lines

    looking at it now, it seems the item.txt is broken.

  • AsadAsad Member
    edited August 2012

    @exussum Try this..

    for LINE in $(cat item.txt) ; do
    echo $LINE
    done

  • something like this should work as well...

    cat item.txt | while read LINE; do
    echo $LINE
    done < my.file

Sign In or Register to comment.