2

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

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

4 Comments

I have one more doubt .. suppose if there is more than one set of data then this will not work right ?
Just updated the data in original question
That changes your original problem completely. May I suggest you create a new question with new sample data and new requirement. I will try to get a solution for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.