How to read the last line of a text file into a variable using Bash? [closed]

对着背影说爱祢 提交于 2019-11-27 16:42:36

问题


I want to read a text file called history.txt that contains multiple lines and store the content of the last line into a variable called "tag".

Thanks


回答1:


tag=$( tail -n 1 history.txt )




回答2:


cat FileName | while read oneline
do
echo "a oneline: $line"
done


来源:https://stackoverflow.com/questions/42987486/how-to-read-the-last-line-of-a-text-file-into-a-variable-using-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!