How to prepend to a file (add at the top)

后端 未结 8 991
逝去的感伤
逝去的感伤 2020-12-20 13:12

Imagine you have a file

sink(\"example.txt\")
data.frame(a = runif(10), b = runif(10), c = runif(10))
sink()

and would want to add some hea

8条回答
  •  攒了一身酷
    2020-12-20 13:18

    Using bash:

    $ cat > license << EOF
    > /* created on 31.3.2011 */
    > /* author */
    > /* other redundant information */
    > EOF
    $ sed -i '1i \\' example.txt
    $ sed -i '1 {
    >    r license
    >    d }' example.txt
    

    Don't know how to do it with one sed command (sed -i -e '1i \\' -e '1 { ... inserts after first line).

提交回复
热议问题