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
 

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本