Append text to file from command line without using io redirection

后端 未结 4 1895
天命终不由人
天命终不由人 2020-12-23 16:00

How can we append text in a file via a one-line command without using io redirection?

4条回答
  •  时光说笑
    2020-12-23 16:58

    You can use the --append feature of tee:

    cat file01.txt | tee --append bothFiles.txt 
    cat file02.txt | tee --append bothFiles.txt 
    

    Or shorter,

    cat file01.txt file02.txt | tee --append bothFiles.txt 
    

    I assume the request for no redirection (>>) comes from the need to use this in xargs or similar. So if that doesn't count, you can mute the output with >/dev/null.

提交回复
热议问题