regex - Using powershell, in a csv doc, need to iterate and insert a character -


so csv file looks like:

j|t|w j|t|w j|t|w 

i'd iterate through, using regex after 2 pipes , content \|.+{2}, , insert tab character `t.

i'm assuming i'd use get-content loop through, i'm unsure of go there.

also...just thought of this, possible line overrun next line, , therefore 2 pipes on different lines, i'm pretty sure makes difference.

-thanks

ok, i'll move comment discussion answer since seems potentially valid solution:

 import-csv .\test.csv -delimiter '|' -header 'one', 'two', 'three' | %{$_.three = "`t$($_.three)"; $_} | export-csv .\test_result.cs 

this works file known have 3 fields. more generic solution, if have ability determine number of fields being exported csv, then:

 import-csv .\test.csv -delimiter '|' -header (1..$fieldcount) | %{$_.$fieldcount = "`t$($_.$fieldcount)"; $_} | export-csv .\test_result.cs 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -