Help with multiple variables into one row in CSV!

I'm new to shell scripting so I'm guessing I'm just not looking at this from the correct angle as this has to be a common task.

What I'm trying to do is take data I've compiled for servers (Name, IPs, HBA WWN's, Storage, etc) and trying to turn that into one row in a CSV file.

So

File1:

ServerA

File2:

192.1.1.1
192.2.2..2

File3:

600.00GB

What I want is:

ServerA, 192.1.1.1, 192.2.2.2, 600GB

I have a script that will run some commands against my storage array, perform some simple awk functions to filter out the data as listed above. I don't have to append the data to seperate files but I figured that would keep it clean. I'd like to run a for loop against a list of servers taht will pull all this data in one server at a time and then append it as one row per server in a single "master" file so I can import it into excel for reporting.

Thanks for your help!

A cat command could put the three files into one, and then a tr command could change the carriage-returns to commas.

Off the top of my head, something like

cat file1 file2 file3 | tr '\n' ',' >file4

But that assumes your 3 files only contain that little bit of data.

1 Like
cat file1 file2 file3 | awk '{ $1=$1 }1' RS= OFS=,

Joey you are spot on my friend. Were I more knowledgabkle with the code I'm sure i could explain this better because I know from working at large companies that its fairly common to use commands, snmpgets, etc to pull raw data then format that to a csv or something similar and then import it into a database for others to access via websites or reporting tools.

I've gotten to the point I can pull this data in via scripts, for loops or whatever but getting it into a format that a database or a spreadsheet app likes afterwards has been the tricky part for me.

So to better explain what I'm doing here is the output of a command that tells me most the info I need about a server, its HBAs and the storage it has:

 
Symmetrix ID      : 00019010111
Host Name         : ServerA
Identifiers Found : 100000001111111
                         100000002222222
 
Device  Cap(MB)  Attr  Dir:P
------  -------  ----  ----
0155          3         7A:0,10A:0
0156          3         7A:0,10A:0
0157          3         7A:0,10A:0
-----------------------------
MB Total: 9

I'm using some simple awk commands to format this data as I listed in the first post. I don't have to use three different files, one would suffice and your cat/tr command combo against that one file would make it one row that I can then redirect to a master list.

So step one of my process would be to:

  1. Run the command above in a loop against a list of a few hundred servers.
  2. Pipe this data to a temp file per server as the loop is executed
  3. Run your cat/tr command against the temp file and >> to my master list
  4. Repeat until I have each server in my master list!

This works perfectly for me but being I'm not very knowledgable on the subject I would love to here yours or anyones opinion on how best to do this as I'm sure this is done often by server admins, network guys, etc for various admin reporting.

Thanks again!