本文介绍了将格式化数据从文本文件导出到csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好 以下是我保存在服务器文本文件中的命令输出。 现在我想用csv导出它,但格式相同。 请帮我这个 root:!:0:0 :: /。root:/ usr / bin / ksh 守护进程:!: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系统管理员:/ home / hrdadm:/ bin / csh orahrd:!:387:151:SAP数据库管理员:/ oracle / HRD:/ bin / csh ipsec:*:205:1 :: / etc / ipsec:/ usr / bin / ksh sshd:*:422:1:OpenSSH需要非登录用户:/ home / sshd:/ usr / bin / ksh hrpadm:!:390:150:SAP系统管理员:/ home / hrpadm:/ bin / csh orahrp:!:391:151:SAP数据库管理员:/ oracle / HRP:/ bin / csh hruser:!:425:215:通用HR用户:/ 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管理员:/ home / best1:/ bin / ksh hrwebm:!:9193:622:Webmp1p2 ToRxPScp:/ home / hrwebm:/ usr / bin / ksh snapp:*:207:12:snapp登录用户:/ usr / sbin / snapp:/ usr / sbin / snappd BMCAudit:!:9327:1:BMCAudit id HD-1294056:/ home / BMCAudit:/ usr / bin / ksh daaadm:!:201:150:SAP系统管理员:/ home / daaadm:/ bin / csh sapadm:!:202:150:SAP系统管理员:/ home / sapadm:/ bin / csh hd7adm:!:301:151:SAP管理员用户:/ home / hd7adm:/ usr / bin / ksh hq7adm:!:302:151:SAP管理员用户:/ home / hq7adm:/ usr / bin / ksh fi001ra:!:203:150:Fiorinda:/ sapio / outbound / ADPQRT:/ usr / bin / csh srvproxy:*:210:0 :服务代理守护进程:/ home / srvproxy:/ usr / bin / ksh lpar2rrd:!:211:1:LPAR2RRD代理用户:/ home / lpar2rrd:/ usr / bin / ksh oracle:* :223:102 :: / home / oracle:/ usr / bin / ksh l1user:*:299:1 :: / home / l1user:/ usr / bin / ksh $ 我尝试过: 尝试执行export-csv,但是它在一行中给了我所有上面的行。解决方案 我尝试过: 尝试执行export-csv,但是它在一行中给我以上所有行。 假设所有':'字符都是字段分隔符,请尝试: (Get-Content input.txt).replace(':',',')| Set-Content output.csv Hi allBelow 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 thisroot:!:0:0::/.root:/usr/bin/kshdaemon:!: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/falseinvscout:!:200:1::/var/adm/invscout:/usr/bin/kshhrdadm:!:386:150:SAP System Administrator:/home/hrdadm:/bin/cshorahrd:!:387:151:SAP Database Administrator:/oracle/HRD:/bin/cshipsec:*:205:1::/etc/ipsec:/usr/bin/kshsshd:*:422:1:Non Login User required by OpenSSH:/home/sshd:/usr/bin/kshhrpadm:!:390:150:SAP System Administrator:/home/hrpadm:/bin/cshorahrp:!:391:151:SAP Database Administrator:/oracle/HRP:/bin/cshhruser:!:425:215:Generic HR User:/home/hruser:/bin/kshldap:*:206:1::/home/ldap:/usr/bin/kshhradmin:!:440:622:HR Admin:/home/hradmin:/bin/kshbest1:!:1005:1:BEST1 Admin:/home/best1:/bin/kshhrwebm:!:9193:622:Webmp1p2 ToRxPScp:/home/hrwebm:/usr/bin/kshsnapp:*:207:12:snapp login user:/usr/sbin/snapp:/usr/sbin/snappdBMCAudit:!:9327:1:BMCAudit id HD-1294056:/home/BMCAudit:/usr/bin/kshdaaadm:!:201:150:SAP System Administrator:/home/daaadm:/bin/cshsapadm:!:202:150:SAP System Administrator:/home/sapadm:/bin/cshhd7adm:!:301:151:SAP Admin user:/home/hd7adm:/usr/bin/kshhq7adm:!:302:151:SAP Admin user:/home/hq7adm:/usr/bin/kshfi001ra:!:203:150:Fiorinda:/sapio/outbound/ADPQRT:/usr/bin/cshsrvproxy:*:210:0:Service Proxy Daemon:/home/srvproxy:/usr/bin/kshlpar2rrd:!:211:1:LPAR2RRD agent user:/home/lpar2rrd:/usr/bin/kshoracle:*:223:102::/home/oracle:/usr/bin/kshl1user:*: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. 解决方案What I have tried:tried doing export-csv, but it is giving me all the above lines in a single line.Assuming all your ':' characters are field separators, try:(Get-Content input.txt).replace(':', ',') | Set-Content output.csv 这篇关于将格式化数据从文本文件导出到csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-25 20:51