bash 读入文件
Suppose we have a file contains the following information, termed input_file:
A 0
B 1
C 2
1. Read file one per line
(1):
while read line
do
printf "$linen"
done <data
(2):
exec 6 <data # create a file handler
while read line 0<&6
do
printf "$linen"
done
exec 6<&- # close file
2. Read and parse each line
while read x y
do
echo $x $y
done <data
3.Read a file with user-specified delimiter
e.g. (file name: data)
A:0
B:1
C:2
IFS=: # set delimiter, delimiter is white space by default
while read x y
do
printf "$xt$yn"
done <data