Tab separated values in awk

后端 未结 6 1579
一向
一向 2020-11-30 21:40

How do I select the first column from the TAB separated string?

# echo \"LOAD_SETTLED    LOAD_INIT       2011-01-13 03:50:01\" | awk -F\'\\t\' \'{print $1}\'         


        
6条回答
  •  情歌与酒
    2020-11-30 22:27

    Use:

    awk -v FS='\t' -v OFS='\t' ...
    

    Example from one of my scripts.

    I use the FS and OFS variables to manipulate BIND zone files, which are tab delimited:

    awk -v FS='\t' -v OFS='\t' \
        -v record_type=$record_type \
        -v hostname=$hostname \
        -v ip_address=$ip_address '
    $1==hostname && $3==record_type {$4=ip_address}
    {print}
    ' $zone_file > $temp
    

    This is a clean and easy to read way to do this.

提交回复
热议问题