March 13, 2017

How to Insert a Line into existing file via Script?

Good day Team,

I am trying to create a script but I am stuck. The file already exists in multiple servers, and we just need to append two more lines in this file.

The below is the scenario details of this exercise.
Existing file at multiple linux machines,
Have to add Two lines in the file via bash Script
Line numbers are known, there’s no specific string to search for
And the two lines has to be in the same file in consecutive order.
Line 65 – TEXTABCD
Line 66 – TEXT DEFG

Answer to the question

you can do this by usingthe sed command in linux 

sed -i  '65i  TEXTABCD' file.txt

sed -i '66i  TEXT DEFG' file.txt

 

Like  (0 likes)
Click Here!