csv file in bash

I'm running a loop using EOF to log into each server in my file serverlist and then run the commands but I want the output to be in csv format in order that I can open it in Excel. I need to be able to remove the new line chars in order that it's csv format but I tried to append  | tr "\n" to the commands but it didn't help. I have another question open where I tried to do is slightly different to here but that didn't work either

#!/bin/bash
>output.log
>excel.csv
for server in `cat serverlist`; do
ssh -q $server <<-EOF 2>&1 >>output.log
sudo su -
hostname | awk -F'.' '{print $1}'; echo "," cat /proc/meminfo | grep MemTotal; echo "," cat /proc/cpuinfo | grep "model name" | head -1 | awk -F':' '{print $2}' ; echo "," cat /proc/cpuinfo | grep -c processor

echo "$info1,$info2,$info3,$info4"
EOF
done

sed -e /^Logged/D -e /^WARNING/D -e /^"Initializing profile"/D -e /^$/D output.log>excel.csv
jaysilverheelsAsked:
Who is Participating?
 
woolmilkporcConnect With a Mentor Commented:
Please look at your other Q - 24346213
It should work as I suggested there.
wmp
 
0
 
tfewsterCommented:
Looks like you had already thought of a way, assigning the output of each command to a variable and then outputting the variables?

info1=`hostname | awk -F'.' '{print $1}'`
info2=`cat /proc/meminfo | grep MemTotal`
info3=`cat /proc/cpuinfo | grep "model name" | head -1 | awk -F':' '{print $2}'
info4=`cat /proc/cpuinfo | grep -c processor`

echo "$info1,$info2,$info3,$info4"

0
 
MikeOM_DBACommented:
Try this:
 

# ...Etc...
hostname | awk -F'.' '{printf "%s,",$1}'; cat /proc/meminfo | grep MemTotal | tr '\n' ',' ; cat /proc/cpuinfo | grep "model name" | head -1 | awk -F':' '{printf "%s,",$2}'; cat /proc/cpuinfo | grep -c processor
# ...Etc...

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.