How to read multiple files at the same time under shell
This article mainly explains "how to read multiple files at the same time under shell". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to read multiple files at the same time under shell".
1. Reading of a single file
Under the shell script, you can read files by line in a variety of ways, as follows:
For line in `cat ${input_filename} `do echo $linedonewhile read linedo echo $linedone
< ${input_filename} 其中第二种方式是将文件重定向到标准输入中 2. 多个文件读取方法 那如何实现同时多个文件的读呢? 我们可以继续利用bash中的文件重定向功能,将文件重定向到特定的文件描述符中,语法如下: nfilen>> filenfile
The n here represents the file descriptor of the open file file, similar to fd in other programming languages. If n is not specified, the default behavior is as follows:
Filefile # same as 0file
We can use the exec command to open the file we want to redirect:
Exec 7