Monday, October 10, 2022

[SOLVED] Convert a vertical line text file to a csv file with parameters

Issue

I tried several ways to transform the text with a column into a summarized csv file based on the contents of the file but I couldn't.

record does not start with comma = first column record that has a comma at the beginning = concatenates with the first

When you find the next record that doesn't have a comma at the beginning, start on another line


Text file to process:

08-ipa_group
,evouth.zip
,zipe.zip
,auth-service.zip
18-ws-api_group
,mocks.zip
,auth-service.zip
,a-service.zip

Output

08-ipa_group,evouth.zip,zipe.zip,auth-service.zip
18-ws-api_group,mocks.zip,auth-service.zip,a-service.zip

Solution

Using awk:

awk -v ORS= '
/^[^,]/ {
  eol()
}
END {
  eol()
}
function eol() {
  if (NR > 1)
    print "\n"
}
1' file


Answered By - oguz ismail
Answer Checked By - Marie Seifert (WPSolving Admin)