Perl Text manipulation

Hello All,

I have been working on a great script to remotely gather server info and store it in a .txt that can be imported to .xls

I have been reading the hostnames that are in the /.shh/known_hosts file so I don't have to mess with passing a password - via ssh (not easy to do , by the way, but posibble) anyway...

I have been stripping the known_hosts file of the following , trying to get a clean hosts.txt file to use as my CONFIRMED list of servers with exchanged keys.

I have removed the follow:

  • ssh key
  • extra charaters and extended hostnames
    (e.g. myserver vs myserver_backup) So I would remove the "_backup"
  • duplicates

So now I have something like the following

So I am looking to manage the text. move all hostnames to the first column and ip's to the 2nd comma separated spot. And move all single column enties to the bottom hostname first then ip's, but that doesn't really matter, just need to know how to manipulate the text, I know your going to say... reg expressions, but I want the easiest way or at least a way I can repeat and reuse for separate tasks.(something I understand)

I will then create an array and print them out via the array.

 
"@lines = map({[split /,/]} @lines);"

Thanks

If having a third column in the spreadsheet is acceptable, then you could keep the string "hostname3.yahoo.com" in the file and the solution would be easy to do if you start with an IP checker written in the shell language, some of which is written here: regular expression for MAC address validation - Page 2