逐行读取文件并在bash中对每个文件执行操作 [英] Read file line by line and perform action for each in bash
本文介绍了逐行读取文件并在bash中对每个文件执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本文件,每行包含一个单词.
I have a text file, it contains a single word on each line.
我需要在bash中循环以读取每一行,然后在每次读取一行时执行一条命令,并将该行的输入用作命令的一部分.
I need a loop in bash to read each line, then perform a command each time it reads a line, using the input from that line as part of the command.
我只是不确定在bash中执行此操作的正确语法.如果有人可以帮助,那就太好了.我需要使用从测试文件中获得的作为参数的行来调用另一个函数.当文本文件中没有更多行时,循环应停止.
I am just not sure of the proper syntax to do this in bash. If anyone can help, it would be great. I need to use the line from the test file obtained as a paramter to call another function. The loop should stop when there are no more lines in the text file.
伪代码:
Read testfile.txt.
For each in testfile.txt
{
some_function linefromtestfile
}
推荐答案
怎么样:
while read line
do
echo $line
// or some_function "$line"
done < testfile.txt
这篇关于逐行读取文件并在bash中对每个文件执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文