Issue
I need to convert a fixed-width file to comma-delimited in Unix.
k12582927001611USNA
k12582990001497INAS
k12583053001161LNEU
k,1258292700,1611,US,NA
k,1258299000,1497,IN,AS
k,1258305300,1161,LN,EU
Solution
Use awk
and substr()
:
awk -v OFS=, '{ print substr($0, 1, 1), substr($0, 2, 10), substr($0, 12, 4), substr($0, 16, 2), substr($0, 18, 2) }' file
Output:
k,1258292700,1611,US,NA
k,1258299000,1497,IN,AS
k,1258305300,1161,LN,EU
Answered By - konsolebox Answer Checked By - Mary Flores (WPSolving Volunteer)