0

I have written a piece of code in Batch script which is somewhat like :

( 
    wmic.exe /node:x.x.x.x computersystem get name
    wmic.exe /node:x.x.x.x computersystem get domain 
    wmic.exe /node:x.x.x.x computersystem get manufacturer 
    wmic.exe /node:x.x.x.x computersystem get model 
    wmic.exe /node:x.x.x.x computersystem get username 
    wmic.exe /node:x.x.x.x computersystem get systemtype
) >> file.txt

The contents of file.txt are :

ABC123  
xyz.com  
Hewlett-Packard  
HP xw4400 Workstation  
ABC123\Administrator  
x64-based PC 

I want above information to be stored in CSV format as follows :

ABC123 , xyz.com , Hewlett-Packard , HP xw4400 Workstation , ABC123\Administrator , x64-based PC 

How can this be achieved?

2 Answers 2

0

Insert echo statements between the wmic calls.

2
  • Okay. Let me try this too. Mar 27, 2014 at 10:45
  • Commas are getting printed on new lines. Mar 27, 2014 at 10:51
0

echo -n # -n do not output the trailing newline

Forget echo, use printf and xarg with delimiter newline -d'\n'

$ cat file.txt 
ABC123
xyz.com
Hewlett-Packard
HP xw4400 Workstation
ABC123\Administrator
x64-based PC


$ cat file.txt | xargs  -d'\n' printf "%s , %s , %s , %s , %s , %s \n"
ABC123 , xyz.com , Hewlett-Packard , HP xw4400 Workstation , ABC123\Administrator , x64-based PC 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .