Note that this will not save the sort, it only presents it as a standard output. To save the sort you need to direct the sort to a file in the standard way:
This however will only change the first instance of word to be replaced, in order to apply to every instance you need to add the global option: `-g` .
As sed is a stream editor, any changes you make using it, will only occur within the standard output , they will not be saved to file. In order to save to file you need to specify a new file output (using `> output.txt`) in addition to the original file. This hasthe benefit of leaving the original file untouched whilst ensuring the desired outcome is stored permanently.
Alternatively, you can use the `-i` option which will make the changes take place in the source file as well as in standard input.
Note that this will overwrite the original version of the file and it cannot be regained. If this is an issue then it is recommended to include a backup command in the overall argument like so:
It is important to sort before attempting to remove duplicates since the `-u` flag works on the basis of the strings being adjacent.
## Split a large file into multiple smaller files: `split`
Suppose you have a file containing 1000 lines. You want to break the file up into five separate files, each containing two hundred lines. You can use `split` to accomplish this, like so:
If you would rather have numeric suffixes, use the option `-d` . You can also split a file by its number of bytes, using the option `-b` and specifying a constituent file size.
## Merge multiple files into one with `cat`
We can use `cat` read multiple files at once and then append a redirect to save them to a file: