big (csv) file line by line and replace the contents of the single line and writing it back to the same file?
E.g. reading a line like this:
10.0.0.0,10.0.0.255,24,"DMZ-1"
Modify it and writing back the line on the same place into the source file with the content:
167772160,167772415,"DMZ-1"
Or would it be better to create an additional file and write the modified lines into it?
If you want to modify in-place you would have to read the file line by line, modify the line if it matches, and write to a temp file. Then you can replace the old file with the temp one.
Read whole file into string, wholeFile = strings.ReplaceAll(wholeFile, "hello", "yellow") then save wholeFile back to the file
Обсуждают сегодня