linux - How to use Bash (sed or any other) command to insert at EOF-nth line -


I searched in stack overflow, but, I did not find any solution. Try hard enough.

I have a file containing this type of code -

  ... {... zero ABC () {if (condition) {x = y ; Z = 0; }}} / EOF  

I x = y; and z = 0; I want to insert some lines of code between .

This can be done in 2 ways -

  1. Pattern x = y; and search for later
  2. do not find the lines in the file -

    NUMOFLINES = $ (wc -l some.txt | awk '{print $ 1} ') TOINSERTLINE = NUMOFLINES-5

Therefore, putting on the value of the tinselline.

More optimal methods are welcome


Answers answered from discussion -

sed -i

>

strong> anubhava . These were closest to what I wanted.

If you want to insert a line after the 5th line sed : Data from here to enter data-file 'file

sed -i.bak $ data- file

File


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -