日期:2014-05-16  浏览次数:20590 次

linux 在文件开头插入文本

  在文件开头插入文本

  通过可在脚本中使用的 ed 单命令行程序,您可以容易地在文件开头插入文本。插入操作是使用 ed 并通过 a 命令将给定文本追加到第 0 行(文件开头)来完成的:

  $ cat file

  This is the end.

  $ (echo '0a'; echo 'This is the beginning.'; echo '.'; echo 'wq') | ed -s file

  $ cat file

  This is the beginning.

  This is the end.