Where test.txt contains:
a string with some extra spaces
line
line
line grdsaaf jgjd
Omit the first line of a file. Useful when replacing a header. Remove the first two lines with +3, etc.
$ tail +2 file.txt
line
line
line grdsaaf jgjd
Collapse multiple spaces into a single space. Note that this will leave one leading or trailing space, if there are multiple leading or trailing spaces in your file.
$ cat test.txt | tr -s " "
a string with some extra spaces
line
line
line grdsaaf jgjd
Collapse multiple newlines into a single newline.
$ uniq test.txt
a string with some extra spaces
line
line
line grdsaaf jgjd
Conditionally run a second command. If the first command fails, run the second one. Redirecting to /dev/null
makes the first command's failure silent. This is useful for a data pipeline that involves making database and database files, like this one.
$ first command > /dev/null 2>&1 || second command