如何通过命令行将可变文本附加到文件的最后一行? [英] How can I append a variable text to last line of file via command line?
本文介绍了如何通过命令行将可变文本附加到文件的最后一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
能否请您告诉我(Linux用户)如何将文本添加到文本文件的最后一行?
could you please tell me how I (a Linux-User) can add text to the last line of a text-file?
我到目前为止有这个:
APPEND='Some/Path which is/variable'
sed '${s/$/$APPEND/}' test.txt
它可以工作,但是$ APPEND添加了变量内容的插入.我知道这样做的原因是我用于sed的单引号(').但是当我简单地用'替换'时,没有文本被添加到文件中.
It works, but $APPEND is added insted of the content of the variable. I know the reason for this is the singe quote (') I used for sed. But when I simply replace ' by ", no text gets added to the file.
您知道解决方案吗?我不坚持使用 sed
,这只是我想到的第一个命令行工具.您可以使用自己喜欢的每个标准命令行程序.
Do you know a solution for this? I don't insist on using sed
, it's only the first command line tool that came in my mind. You may use every standard command line program you like.
我刚刚尝试过:
$ sed '${s/$/'"$APPEND/}" test.txt
sed: -e Ausdruck #1, Zeichen 11: Unbekannte Option für `s'
推荐答案
echo "$(cat $FILE)$APPEND" > $FILE
这就是我所需要的.
这篇关于如何通过命令行将可变文本附加到文件的最后一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文