echo from lines of a file

26,809

That's better

cat myfile.txt | while read line; do
    echo "$line"
done

or even better (doesn't launch other processes such as a subshell and cat):

while read line; do
    echo "$line"
done < myfile.txt

If you prefer oneliners, it's obviously

while read line; do echo "$line"; done < myfile.txt
Share:
26,809
patz
Author by

patz

Updated on July 10, 2022

Comments

  • patz
    patz almost 2 years

    i have a file "myfile.txt" that have the next content:

    hola mundo
    hello word
    

    and i want work with every line

    for i in `cat myfile.txt`; do echo $i; done
    

    i hope this give me

    hola mundo
    hello word
    

    firts one line, then the other, but get

    hola
    mundo
    hello
    word
    

    as I can demanding results until newline instead of each space?

    ty all

  • Sri Hari Vignesh
    Sri Hari Vignesh over 7 years
    In the second version, why do you add the file name in the end and how does it work? especially the last line done < myfile.txt