Re-writing data on a file in SD card

I am using SD Lib and want to over-write some data.
I am familiar with file.position() and file.seek() functions.

My TEST.txt file contains this data:

116-130-150-170-188-211-1-2750+23370

I want to replace 170 with 172. Below is what I have done so far,

  SD.open("test.txt", FILE_WRITE);
  file.seek(12);
  file.print("172");
  //file.write("172", 3);
  file.close();

But, there is no change in the file after running the code.

i could not figure out, where I am wrong.

If you read the file seek documentation, you will note the position parameter is a long integer, not what you have written.
Paul

Paul_KD7HB:
If you read the file seek documentation, you will note the position parameter is a long integer, not what you have written.
Paul

Okay. But it is not working with

SD.open("test.txt", FILE_WRITE);
//file.seek(12UL);
unsigned long pos = 12;
file.seek(pos);
file.print("172");
file.close();

Would appreciate if you could kindly get it done.

Documentation again: You must READ the data before you can change it.
Paul

I have read the document and have understood that the parameter within the parenthesis of file.seek() function must be an unsigned long.

After seeking the position, I read the file using file.read() function and then I file.print() the new data. But failed. Definitely, I am wrong somewhere.

Would you be kind enough, to show me how to write the code to achieve my goal. That will help me to grasp the idea more easily. Thanks in advance.