separate fields by comma using bash

前端 未结 8 1416
滥情空心
滥情空心 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条回答
  •  再見小時候
    2021-01-25 01:50

    Another option is to use a CSV parser:

    ruby -rcsv -ne '
      puts CSV.generate_line(
             CSV.parse_line($_.strip, {:col_sep => " ", :quote_char => "'\''"}
           ), {:force_quotes => 1}) 
    '  file
    
    "12123","QA test case 1","QA environment"
    "12234","UAT test case 1","UAT environment"
    

提交回复
热议问题