How can I use a file in a command and redirect output to the same file without truncating it?

前端 未结 14 2991
终归单人心
终归单人心 2020-11-21 22:11

Basically I want to take as input text from a file, remove a line from that file, and send the output back to the same file. Something along these lines if that makes it any

14条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 22:51

    Try this

    echo -e "AAA\nBBB\nCCC" > testfile
    
    cat testfile
    AAA
    BBB
    CCC
    
    echo "$(grep -v 'AAA' testfile)" > testfile
    cat testfile
    BBB
    CCC
    

提交回复
热议问题