Tabbing the printed fields evenly using awk

后端 未结 3 1730
天涯浪人
天涯浪人 2021-01-27 07:09

i need help using awk. Thanks

i have a file it contains the following

text.txt  
The Hunger Games:Suzanne Collins:1:2:3
Weapon X:Stan Lee:3:4:5
         


        
3条回答
  •  不思量自难忘°
    2021-01-27 08:09

    Try this to get tab spacings as in your example:

    awk -F: '{if(NR==2)$2="\t"$2;print $1, $2, $3, $4, $5}' OFS="\t" BookDB.txt
    

    Setting : as field seperator and \t as output field seperator. Then for the second line (NR==2), add one extra tab for the second field. Then print the fields.

    Or even simpler (if it is acceptable for you):

    sed "s/:/\t/g" BookDB.txt
    

提交回复
热议问题