Popular `file manipulation` terminal commands

Delete all lines that contain a specific string from a text file

Deletes all lines from a text file that contain a specific string. Pass the `-i` flag to modify the file in place.

Authored by: SiegeX

Delete empty lines in a file

Deletes all lines that contain only whitespace from a file.

Authored by: Kent

Insert a line at a specific line number

Inserts a line of text into a specific line number of a file using sed. The `-i` flag indicates the file is modified in place.

Authored by: glenn jackman

Print the nth line of a file

Uses sed to print the the the nth line of a file. This is faster than most other solutions since `NUMq` immediately quits when the line number is hit.

Authored by: anubhava

Recursively find and replace within a directory

Replaces all occurrences of a string recursively within a directory

Authored by: Anatoly

Recursively search through files that match an extension

Recursively searches all the files that end in `extension` for the term `search_term`.

Authored by: HoldOffHunger

Remove the first line of a text file

Removes the first line line of a file using tail. Tail defaults to printing the first `x-1` lines, so `+2` indicates it should skip the first line.

Authored by: Aaron Digulla

Replace newline with a space in a file

Replaces all newlines with a space, by using the `tr` command.

Authored by: dmckee --- ex-moderator kitten

Sort a file by line length

Sorts a text file by line length (including spaces). The `-s` flag indicates that any lines that are the same length are kept in the relative order that they occurred in the input.

Sum all numbers in a file

Uses awk to sum all the numbers in a file. This command is also resilient to big numbers since it internally converts each number to a string.

Authored by: devnull