Convert .txt file to .csv with header in bash

后端 未结 3 2023
花落未央
花落未央 2020-12-20 10:08

.txt looks like:

2013-04-10;248179;5431;5375.30€;1.49
..
..
..

I need a .csv file with a Header:

Date       Visit   Login           


        
3条回答
  •  星月不相逢
    2020-12-20 10:34

    This is a pure bash solution.Store the headers in an array and set IFS to tab and then echo the header. Loop through the file with read, set IFS to ; on the way in, set IFS to tab and run echo on the way out.

    headers=(Date       Visit   Login  Euro      Rate)
    ((IFS=$'\t'; echo "${headers[*]}"); 
    while IFS=';' read -r -a arr; do
    (IFS=$'\t'; echo "${arr[*]}";)
    done < test.fil) > test.csv
    

提交回复
热议问题