Hi I need a little help
I need to change the first value of the first column of a csv
"A"; "B"; "C"; "D"
"1"; Rome";" Italy";"12/1/2023"
"2"; "Milan";"Italy";"2/11/2023"
"3"; "Firneze"; "Italy";"13/3/2021"
Riuslt
"A"; "B"; "C"; "D"
"one"; Rome";" Italy";"12/1/2023"
"two"; "Milan";"Italy";"2/11/2023"
"three"; "Firneze"; "Italy";"13/3/2021"
using the replace command obviously also changes the date
-replace '1' , 'one'
this is the wrong result
"A"; "B"; "C"; "D"
"one"; Rome";" Italy";"12/one/2023"
you can help me?
Questo è il file csv originario
"cycle";"support";"eol";"latest";"releaseDate";"OS"
"9";"2027-05-31";"2027-05-31";"9";"2021-09-15";"Centos"
"stream-8";"2024-05-31";"2024-05-31";"8";"2019-09-24";"Centos"
"8";"2021-12-31";"2021-12-31";"8 (2111)";"2019-09-24";"Centos"
"7";"2020-08-06";"2024-06-30";"7 (2009)";"2014-07-07";"Centos"
"6";"2017-05-10";"2020-11-30";"6.10";"2011-07-10";"Centos"
Questo è quello di cui ho bisogno
"cycle";"support";"eol";"latest";"releaseDate";"OS"
"Release 9.";"2027-05-31";"2027-05-31";"9";"2021-09-15";"Centos"
"Release stream 8.";"2024-05-31";"2024-05-31";"8";"2019-09-24";"Centos"
"Release 8.";"2021-12-31";"2021-12-31";"8 (2111)";"2019-09-24";"Centos"
"Release 7.";"2020-08-06";"2024-06-30";"7 (2009)";"2014-07-07";"Centos"
"Release 6.";"2017-05-10";"2020-11-30";"6.10";"2011-07-10";"Centos"
CodePudding user response:
Thanks for the reply, but it still doesn't work
This is the originating csv file
"cycle";"support";"eol";"latest";"releaseDate";"OS"
"9";"2027-05-31";"2027-05-31";"9";"2021-09-15";"Centos"
"stream-8";"2024-05-31";"2024-05-31";"8";"2019-09-24";"Centos"
"8";"2021-12-31";"2021-12-31";"8 (2111)";"2019-09-24";"Centos"
"7";"2020-08-06";"2024-06-30";"7 (2009)";"2014-07-07";"Centos"
"6";"2017-05-10";"2020-11-30";"6.10";"2011-07-10";"Centos"
This the ones I need
"cycle";"support";"eol";"latest";"releaseDate";"OS"
"Release 9.";"2027-05-31";"2027-05-31";"9";"2021-09-15";"Centos"
"Release stream 8.";"2024-05-31";"2024-05-31";"8";"2019-09-24";"Centos"
"Release 8.";"2021-12-31";"2021-12-31";"8 (2111)";"2019-09-24";"Centos"
"Release 7.";"2020-08-06";"2024-06-30";"7 (2009)";"2014-07-07";"Centos"
"Release 6.";"2017-05-10";"2020-11-30";"6.10";"2011-07-10";"Centos"
CodePudding user response:
import the CSV by using import-csv
, by doing so you get an array of objects back and so you can simply target only the property you want to update, e.g.
#load csv
$csv = import-csv [path] -delimiter ";"
#loop and set value of property cycle
$csv | %{
$_.cycle = 'Release ' $_.cycle
}
#output new csv to file
$csv | export-csv [path]