问题
I have data in the below format
APP_OWNER : hari
APP_AREA : Work:Business Area:AUS
APP_ID : 124080
I want the data to be converted to below format.
APP_OWNER,APP_AREA,APP_ID
hari,Work:Business Area:AUS,124080
I can convert one line but how to do it with 3 lines at the same time?
My Attempt with one line
sed '0,/: /s//\n/' test.txt
Regards
回答1:
You may try this awk
solution:
awk -F '[[:blank:]]+:[[:blank:]]+' '{
v1 = (v1 == "" ? "" : v1 ",") $1
v2 = (v2 == "" ? "" : v2 ",") $2
}
END {
print v1 ORS v2
}' file
APP_OWNER,APP_AREA,APP_ID
hari,Work:Business Area:AUS,124080
来源:https://stackoverflow.com/questions/65497666/convert-rows-to-columns-shell-script