I've tried to write a code in which: 

```
  %# Matlab reads a notepad file.

  f_id=fopen('n1.txt','r');
  reports=textscan(f_id, '%s', 'Delimiter', '\n')
  fclose(f_id)
  reports_saved=reports{1} ;
  P='blah blah'

```

**EDIT:** 

```
 goes to a specific line of the text file.
X=ftell(f_id)
Ai=fseek(f_id, 0, 'cof')
 fprintf(f_id,'%s', P);
 fclose(f_id)

```

The 1st line where 'cof' pointer was over written. Now, **Problem 1:** If the new text is shorter than the existing one, characters from the existing text remains after overwriting. Any hints why ? **Problem 2:** 'fseek' only allows to go to beginning, current position or end of the file. Is there any way to make the pointer move randomly like going to text no4 /5. Note, each text has got a blank line in between them. 

**Any help is appreciated.**