1

I would like to replace a specific line range with Nan values. My line range is defined by variables for the first and last line I would like to replace, so for example:

startrow=3
endrow=6

Input file:

1
4
3
2
6
1
3
4

Desired output file:

1
4
Nan
Nan
Nan
Nan
3
4

I think this should be possible using sed. Help much appreciated!

2

You can use startline,endlineCOMMAND syntax with sed. For example:

$ sed "${startrow},${endrow}s/.*/Nan/" file.txt

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.