separate fields by comma using bash

前端 未结 8 1429
滥情空心
滥情空心 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:44

    The solution is to walk through every character in the record (while read -n 1), joining every non-space character as one element value and all characters enclosed in single quotes (or quoted single quotes in your option (\'). Everytime you complete a unit (reaching space or newline), append it to an array. When encountering a newline or reaching EOF, end the record and print the record array in your format. The cycle begins again with record array cleared.

    Want a source code? Show me your work first. :)

提交回复
热议问题