LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-18-2008, 06:43 PM   #1
Adrnalnrsh
LQ Newbie
 
Registered: Sep 2005
Posts: 17

Rep: Reputation: 0
[SHELL] Output formatting


I am looking for a way to format the output of this string into comma separated values (.csv) so I can import into excel.

Also I want to remove any white space generated by the commands, particularly the dmidecode as the output has lots of space in front of Serial Number.

Code:
#!/bin/bash

for i in $( cat "ipaddresses.txt" ); do     # list of ip addresses 
echo "$i" >> host_details.txt;
ssh $i 'hostname ; dmidecode | grep "Serial Number" | head -1 ; free -m | grep Mem | awk '\''{ print $1,$2 }'\'' ; uname -r ; ' >> host_details.txt
done


Current output looks like.


[root@server user]# cat test23.txt
server.domain.com
-WHITE SPACE--Serial Number: F3FF071
Mem: 2007
2.4.21-27.ELsmp

Last edited by Adrnalnrsh; 09-18-2008 at 06:45 PM.
 
Old 09-18-2008, 09:13 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, this is pretty horrible, but as no one else has chipped in...

Code:
IFS="
"
for rec in `cat t.t`
do
    echo -n "$rec," >>t1.t
done
sed -i -e 's/[ ]\+/ /g' t1.t
sed -i -e 's/,$//' t1.t
echo >> t1.t
where t.t is your test23.txt
 
Old 09-19-2008, 01:15 AM   #3
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Code:
#!/bin/bash

for i in $(<"ipaddresses.txt" ); do     # list of ip addresses 
  echo "$i" >> host_details.txt;
  ssh $i "hostname ; dmidecode | sed -n '/Serial Number/ p' ; free -m | awk '/Mem/ { print \$1,\$2 }' ; uname -r ;" | tr "\n" "," >> host_details.txt
done
 
Old 09-22-2008, 10:29 AM   #4
Adrnalnrsh
LQ Newbie
 
Registered: Sep 2005
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by burschik View Post
Code:
#!/bin/bash

for i in $(<"ipaddresses.txt" ); do     # list of ip addresses 
  echo "$i" >> host_details.txt;
  ssh $i "hostname ; dmidecode | sed -n '/Serial Number/ p' ; free -m | awk '/Mem/ { print \$1,\$2 }' ; uname -r ;" | tr "\n" "," >> host_details.txt
done
Thanks worked perfect
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting output of find suitable for rm JussiKp Linux - Newbie 3 12-24-2006 03:00 AM
Formatting output krock923 Programming 2 06-07-2006 07:26 AM
formatting date output grob115 Linux - Newbie 2 01-28-2006 08:03 AM
Formatting output of ls doodar Linux - Newbie 29 07-29-2004 01:25 PM
need hlp formatting output from ls test* Evan P. Programming 1 11-06-2003 08:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration