I read the help read
page, but still don\'t quite make sense. Don\'t know which option to use.
How can I read N lines at a time using Bash?
Simplest method - pretty self-explanatory. It is similar to the method provided by @Fmstrat, except the second read
statement is before the do
.
while read first_line; read second_line
do
echo "$first_line" "$second_line"
done
You can use this by piping multiline input to it:
seq 1 10 | while read first_line; read second_line
do
echo "$first_line" "$second_line"
done
output:
1 2
3 4
5 6
7 8
9 10