我试图仅从报告的第一行中删除引号。报告的其余部分,报价都很好。我尝试了这个,但它删除了第一行之后的所有内容:
(gc daily_report_yyyymmdd.csv -First 1) |
% {$_ -replace '"', ""} |
Out-File daily_report_yyyymmdd.csv -Fo -En Ascii
标题
ORDER_ID,"PRIORITY_STATUS","PRODUCT_CLASS","PLAN_NAME","CONTRACT_ID","GROUP_NAME","CREATION_DATE","TECH_RESPONSE_DATE","RPH_RESPONSE_DATE","CLOSE_DATE","MEMBER_ID","FIRST_NAME","LAST_NAME","DRUGNAME","PHYSICIAN_FIRST_NAME","PHYSICIAN_LAST_NAME","NPI","RPH First Name","RPH Last Name","CSR First Name","CSR Last Name","QA First Name","QA Last Name","OutBound Call Notes","RFI Sent","COV_DETERM_TYPE","ORIGIN_OF_REQUEST","FORMULARYSTATUS","BENEFIT","ORDER_STATUS","RATIONALEBRIEFDESC","EARLY_CLOSE_CODE","TAT from Order Create (Hours)","TAT from Fax Receipt (Hours)"
第一行
2727770,"Standard","TESTMAI","TESTMAI","PIZZA ","DOUGH","2017-11-29 18:11:18.816000","2017-12-01 08:53:30.000000","2017-11-07 09:15:32.000000","2017-12-01 08:53:30.665000","123456789","TEST","USER","Bystolic 10 mg tablet","TEST","PEOPLE","1234657984","TESTER","TEST","TESTER","TEST","TESTER","TEST","","N","","Provider Fax","On Formulary","Pharmacy Benefit","Early Close","The medication requested is a non-preferred medication. The member must try/fail at least one preferred agent for a period of 30 days or more before approval of a non-preferred agent. The preferred a","ELCL","38","38"
答案 0 :(得分:0)
您正在选择一行,然后将其写回同一文件,基本上用该行覆盖整个文件。结果:其他所有内容都被删除。
我并不太关心你在这里想要达到的目标。如果您确定它始终是第一行,您可以试试这个。
$File = gc daily_report_yyyymmdd.csv
$File[1] -replace '"', ""
$File | Out-File daily_report_yyyymmdd.csv -Fo -En Ascii
不会为可扩展性留下很大空间
答案 1 :(得分:0)
我在PowerShell中将DOS转换为UNIX,它处理了我的CR问题:
$csvdata = [io.file]::ReadAllText('in.csv') | % {$_ -replace "`r",""}
[io.file]::WriteAllLines('out.csv', $csvdata)