Add a header to a tab delimited file

前端 未结 8 842
北恋
北恋 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:31

    Using sed no need of temp file

    sed -i "s#^#name\tage\tuniversity\tcity#g#"
    

    Demo:

    
    $ cat file1.txt
    roger\t18\tcolumbia\tnew york\n
    albert\t21\tdartmouth\tnew london\n
    etc...
    $ sed -i "s#^#name\tage\tuniversity\tcity#g#" file1.txt $ cat file1.txt
    name    age     university      cityroger\t18\tcolumbia\tnew york\n
    name    age     university      cityalbert\t21\tdartmouth\tnew london\n
    name    age     university      cityetc...
    $
    
    

提交回复
热议问题