Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all

Below is the output of a command i kept in a text file for a server.

Now i want to export it in csv but in same format.

Please help me in this

root:!:0:0::/.root:/usr/bin/ksh
daemon:!:1:1::/etc:
bin:!:2:2::/bin:
sys:!:3:3::/usr/sys:
adm:!:4:4::/var/adm:
nobody:!:4294967294:4294967294::/:
lpd:!:9:4294967294::/:
lp:*:11:11::/var/spool/lp:/bin/false
invscout:!:200:1::/var/adm/invscout:/usr/bin/ksh
hrdadm:!:386:150:SAP System Administrator:/home/hrdadm:/bin/csh
orahrd:!:387:151:SAP Database Administrator:/oracle/HRD:/bin/csh
ipsec:*:205:1::/etc/ipsec:/usr/bin/ksh
sshd:*:422:1:Non Login User required by OpenSSH:/home/sshd:/usr/bin/ksh
hrpadm:!:390:150:SAP System Administrator:/home/hrpadm:/bin/csh
orahrp:!:391:151:SAP Database Administrator:/oracle/HRP:/bin/csh
hruser:!:425:215:Generic HR User:/home/hruser:/bin/ksh
ldap:*:206:1::/home/ldap:/usr/bin/ksh
hradmin:!:440:622:HR Admin:/home/hradmin:/bin/ksh
best1:!:1005:1:BEST1 Admin:/home/best1:/bin/ksh
hrwebm:!:9193:622:Webmp1p2 ToRxPScp:/home/hrwebm:/usr/bin/ksh
snapp:*:207:12:snapp login user:/usr/sbin/snapp:/usr/sbin/snappd
BMCAudit:!:9327:1:BMCAudit id HD-1294056:/home/BMCAudit:/usr/bin/ksh
daaadm:!:201:150:SAP System Administrator:/home/daaadm:/bin/csh
sapadm:!:202:150:SAP System Administrator:/home/sapadm:/bin/csh
hd7adm:!:301:151:SAP Admin user:/home/hd7adm:/usr/bin/ksh
hq7adm:!:302:151:SAP Admin user:/home/hq7adm:/usr/bin/ksh
fi001ra:!:203:150:Fiorinda:/sapio/outbound/ADPQRT:/usr/bin/csh
srvproxy:*:210:0:Service Proxy Daemon:/home/srvproxy:/usr/bin/ksh
lpar2rrd:!:211:1:LPAR2RRD agent user:/home/lpar2rrd:/usr/bin/ksh
oracle:*:223:102::/home/oracle:/usr/bin/ksh
l1user:*:299:1::/home/l1user:/usr/bin/ksh
$


What I have tried:

tried doing export-csv, but it is giving me all the above lines in a single line.
Posted
Updated 3-Aug-17 4:21am

1 solution

Assuming all your ':' characters are field separators, try:
(Get-Content input.txt).replace(':', ',') | Set-Content output.csv
 
Share this answer
 
Comments
TesmoKava 3-Aug-17 11:05am    
Griff, it is an entire output with no separators.

output should be something like:

Server command output
a abd above data
OriginalGriff 3-Aug-17 11:12am    
None of which is in your sample! Do you want to try again, explaining what - exactly - you want in the CSV file from the input you showed? We can't read you mind here! :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900