Ever need to convert lines in vertical format to a CSV formatted format or a format that's like a Python list? Paste command in Linux can easily do this. Example data: server01_local server02_local server03_local server04_local server05_local server01_cluster server02_cluster server03_cluster server04_cluster server05_cluster Convert to CSV format or a Python list format with commas as delimiters. Here's the command that does the trick: paste -sd ',' file1.txt > file2.txt (see image below for the command) That's it, that's the magic; the command above will convert the file to a CSV formatted format. Then it can be feed to a Python program for further processing or automation. Example image output: Or it can be processed by a bash script, like this sample code below using Awk and for loop. Till next time. Keep exploring. Work Smart and use the technology to make your life easier. Put God first always. Everything else will fall into place and Trust His Timin...
Make the world a better place by sharing knowledge, ideas and anything that you can give that comes from the heart.