0

I have a text file like this:

lorem ipsum

some text

even more lorem ipsum

How do I select that "some text" bit of the file and and write to it eg. "more lorem ipsum".
Note: The "some text" section will not have a constant value.
Thanks in advance!

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Nov 6, 2021 at 10:05

1 Answer 1

2

Using line-replace npm module:

const lineReplace = require('line-replace')
lineReplace({
  file: 'yourtextfilename.txt',
  line: 3, // line number starts from 1 
  text: 'more lorem ipsum',
  addNewLine: true,
  callback: ({ file, line, text, replacedText, error }) => {}
})

PS: This question has been already answered multiple times before, please do your own research before posting a question.

Sign up to request clarification or add additional context in comments.

2 Comments

This question has been already answered multiple times before” If so, flag as a duplicate and don’t answer it.
But he looks like a beginner so I just gave an even simpler answer that probably isn't in the other answers. Also, I can't flag for duplicates yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.