-1

I have a very large text file that is difficult to open in text editors.

Lines 12 - 15 are:

1 15.9994
2 24.305

Atoms

I would like to add:

3 196 to line 14 and then have a blank line between 3 196 and Atoms like it is currently. I tried:

sed '14 a <3 196>' file.data

But it did not seem to change anything. Anyone know of how I can do this?

Ben
  • 332
  • 1
  • 3
  • 13
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Apr 27 '18 at 22:29
  • Here are your duplicates: [Insert a line at specific line number with sed or awk](https://stackoverflow.com/q/6537490/608639), [Add text to file at certain line in Linux](https://stackoverflow.com/q/15157659/608639), [Insert text at specific line number](https://unix.stackexchange.com/q/271475/56041), [Insert multiple lines of text before specific line using sed](https://stackoverflow.com/q/32007152/608639), etc. – jww Apr 28 '18 at 17:06

1 Answers1

-1

Normally, sed only writes out the changes. It does not modify the file.

If you want the input file to be modified, you can use GNU sed -i:

sed -i '14 a <3 196>' file.data

Before:

[...]
9
10
11
1 15.9994
2 24.305

Atoms
16
17
[...]

After:

[...]
9
10
11
1 15.9994
2 24.305

<3 196>
Atoms
16
17
[...]

Note: If you want it after line 13 instead of 14, change 14 to 13 in your code. Similarly, if you wanted 3 196 instead of <3 196>, change <3 196> to 3 196 in your code.

that other guy
  • 116,971
  • 11
  • 170
  • 194