1
$\begingroup$

I have a file as following:

  cat data.m
  1
  2
  3
  x+y
  2 x + 3 y

So it contains rows containing numeric numbers or expressions, which at this stage is not a column per se but upon substitution of say x=1 and y=2 it will give an output column as:

  cat output.m
  1
  2
  3
  3
  8

I want to save the whole file into this output file after substitution of x and y. Is there any way to do it? The way I was thinking is whether I can loop over the file data.m and in the process substitute x and y. Can anyone help me?

$\endgroup$
3
$\begingroup$
Block[{x = 1, y = 2},
  Export["out.m", ReadList["data.m"], "Table"]
]

 FilePrint@"out.m"

1
2
3
3
8

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.