Append file contents to the bottom of existing file in Bash [duplicate]

冷暖自知 提交于 2019-12-18 10:14:31

问题


Possible Duplicate:
Shell script to append text to each file?
How to append output to the end of text file in SHELL Script?

I'm trying to work out the best way to insert api details into a pre-existing config. I thought about using sed to insert the contents of the api text file to the bottom of the config.inc file. I've started the script but it doesn't work and it wipes the file.

#!/bin/bash

CONFIG=/home/user/config.inc
API=/home/user/api.txt

sed -e "\$a $API" > $CONFIG

What am I doing wrong?


回答1:


This should work:

 cat "$API" >> "$CONFIG"

You need to use the >> operator to append to a file. Redirecting with > causes the file to be overwritten. (truncated).



来源:https://stackoverflow.com/questions/13181725/append-file-contents-to-the-bottom-of-existing-file-in-bash

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