【发布时间】:2020-02-20 21:14:09
【问题描述】:
我想写一个 bash/bash 脚本,它可以包含 while 循环,它会从头到尾逐行读取文本文件,并触发记录器从当前行创建一个日志文件。
有没有人知道如何实现这一目标?
代码:
#!/bin/bash
# A shell script to read file line by line
filename="/home/user/logs.txt"
while read line do
# $line variable contains current line read from the file
# display $line text on the screen or do something with it.
logger "$line"
done < $filename
【问题讨论】:
-
到目前为止你尝试过什么?你说的是哪个记录器?
-
#!/bin/bash # 逐行读取文件的 shell 脚本 filename="/home/user/logs.txt" while read line do # $line 变量包含从file # 在屏幕上显示 $line 文本或对其进行处理。 logger "$line" done
-
我现在已经在你的问题中添加了代码,但是下次你不应该把它放在 cmets 中。不仅更难阅读,没有人会在那里寻找它;-)
标签: bash shell file ubuntu terminal