Bash:将文本文件的最后一行读入变量

时间:2021-07-23 15:46:20

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".

我想读一个名为history.txt的文本文件,其中包含多行,并将最后一行的内容存储到名为“tag”的变量中。

Thanks

2 个解决方案

#1


8  

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

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

#2


-4  

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

#1


8  

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

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

#2


-4  

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