Shell script to convert text file to delimited form

Many times we may need to convert normal text files to comma delimited or any delimited forms. When dealing with Ansible, a comma-delimited form is very useful. Excel we can use but on Linux console, we can use follow two-liner to do work for us.

Bash Shell script to convert text file to delimited CSV format. Consider I have 300 hosts to gather some ifup -a o/p using Ansible playbook. I have an inventory of 2000 hosts with my Ansible. so I can pass selected hosts as variable to Ansible playbook in comma-delimited form. How to do it in Linux Shell in a quick way?

[root@localhost work]# cat
sv_string=$(paste -sd, hosts)
echo $sv_string 
[root@localhost work]# 


[root@localhost work]# ./,,,,,
[root@localhost work]# cat hosts







Leave a Reply

Your email address will not be published. Required fields are marked *