Insert text on a particular line number

Insert Text on a particular line number (SED)

SED Tricks

Ever needed to create a script which edits a file and places a string on a particular line (iptables etc...), well I came across this sed command which would do just that:

sed '[line number]i\ [my text here]' [filename] > [output filename]

You can even insert text from a file

sed '[line number]r [location of file]' [filename] > [output filename]

Browse Space

- Pages
- News
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

 

Other Features

Add Content

- Add Comment