Convert space separated file to tab separated file

前端 未结 2 1162
一生所求
一生所求 2021-01-23 21:21

I was trying to use awk to convert a space delimited file into a tab delimited file. To my surprise this didn\'t work as expected:

awk -vOFS=$\'\\t\' \'{print}\'         


        
2条回答
  •  执笔经年
    2021-01-23 21:48

    Try this:

    awk -v OFS='\t' '{$1=$1}1' file
    

    If you just set OFS, it does not do anything. By setting $1 to $1 it will use the OFS since field has changed. 1 is always true, so it will print the line. Same as {print}

提交回复
热议问题