[quote="adrnalnrsh"]
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.
#!/bin/bash
for i in $( cat "ipaddresses.txt" ); do # list of ip addresses
There is no need for cat (and it will cause the script to fail if any lines in the file contain spaces).
while read i
do
: do whatever....
done < ipaddresses.txt
Sorry to thread jack, could you explain that a little more please?
Say I have a file with 5 ip address's:
172.16.31.248
172.16.31.249
172.16.31.250
172.16.31.251
172.16.31.252
and I wanted to ping each one of them, I'd typically do something like:
#!/usr/bin/bash
for i in `cat ips.out`;do ping $i;done
What is it that is wrong with this method?
I mean I wouldn't normally put it in a script...but you know what I mean.
In this case, it doesn't matter all that much, but it's an inefficient method. It uses cat (an external command, and therefore slow) unnecessarily, and causes extra work for the shell in splitting the output of cat into separate arguments.
However, if any of the lines contained spaces, it would also split the line and $i would be assigned each word separately.
Right, this much I follow, I guess what I'm asking is, in the example you gave, what is I? I understand why my way is ineffective, but I don't understand the syntax of your "while read..." command. I thought read was for reading from stdin? Maybe I'm misunderstanding the intent of the op's script...