Operating on Lines by Number
Explore how to use sed commands to operate on specific text lines by number. Learn to comment, insert, append, change, or delete lines, and replace placeholders with content from other files. This lesson helps you control text streams and edit files efficiently using line references in the command line.
Finding a line
We usually find a line with text or a regular expression, but we can also find it by its number. Let’s go back to the urls.txt file and explore this further.
Let’s comment on the first line of the file. We use the following command to target the first line and insert the comment character:
$ sed -e '1 {s/^/#/}' urls.txt
To comment on lines 2 through 4 of the file, we use ...