separate fields by comma using bash

前端 未结 8 1570
滥情空心
滥情空心 2021-01-25 01:07

How do I place commas between fields?

Input data

12123 \'QA test case 1\' \'QA environment\'   
12234 \'UAT test case 1\' \'UAT environment\'  
         


        
8条回答
  •  Happy的楠姐
    2021-01-25 02:01

    Try this awk:

    awk -F" '" '{ print $1, $2, $3 }' OFS=", '" data
    

    or using a BEGIN block:

    awk -F" '" 'BEGIN {OFS="," FS} { print $1, $2, $3 }' data
    

    In either case, the FS is being set to ' (space + "'") and OFS is being set to "," + '. It's based on the assumption ' is a validly unique field separator and all input data is formatted/arranged as in the question.

提交回复
热议问题