manish soni
manish soni

Reputation: 575

How to convert a txt file to yml file by bash command?

I have a txt file it has some contents, and i want to convert it into yml format using linux commands.

Sample Txt File

mac
linux
windows

And i want following output. like i want to add "os" keyword and convert this to yml by linux command.

os:
   - mac
   - linux
   - windows

Can Anyone try me to get this, Thanks

Upvotes: 0

Views: 2634

Answers (1)

Inian
Inian

Reputation: 85683

On mikefarah/yq, you could just read the input text file contents as a raw string and then split on a space.

Note that, this is fragile, because it doesn't hold well when your string contents contain a space themselves.

yq e '{"os": split(" ")}' yaml

Upvotes: 1

Related Questions