LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   read multiple line from file in bash (https://www.linuxquestions.org/questions/linux-newbie-8/read-multiple-line-from-file-in-bash-4175502206/)

hoi 04-18-2014 01:32 PM

read multiple line from file in bash
 
Content of myfile.txt:
1 1 1 1
1 1 2 2

code:
read a b c d < myfile.txt
echo $a
echo $b
echo $c
echo $d

output:
1
1
1
1

How to read many line from file one by one??

hoi 04-18-2014 01:40 PM

got answer..
cat file | while read a b c d
do
echo $a
echo $b
echo $c
echo $d
done

grail 04-19-2014 01:16 AM

Try doing the following after the loop:
Code:

echo $a
See if you get what you think you should?

kooru 04-19-2014 01:28 AM

Code:

while read line
do
echo $line
done < file



All times are GMT -5. The time now is 12:13 AM.