Add a header to a tab delimited file

前端 未结 8 861
北恋
北恋 2020-12-14 21:46

I\'d like to add a header to a tab-delimited file but I am not sure how to do it in one line in linux.

Let us say my file is:



        
8条回答
  •  盖世英雄少女心
    2020-12-14 22:51

    There isn't a "prepend" operator like the "append" operator >>, but you can write the header to a temp-file, copy your file's contents into the temp-file after that, and move it back:

    echo -e "name\tage\tuniversity\tcity" | cat - yourfile > /tmp/out && mv /tmp/out yourfile
    

提交回复
热议问题