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?

0

Insert echo statements between the wmic calls.

  • Okay. Let me try this too. – Mandar Shinde Mar 27 '14 at 10:45
  • Commas are getting printed on new lines. – Mandar Shinde Mar 27 '14 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 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.