Skip to content

Instantly share code, notes, and snippets.

@hancush
Last active January 24, 2018 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hancush/dd15e847c261a545c98e997e448815f7 to your computer and use it in GitHub Desktop.
Save hancush/dd15e847c261a545c98e997e448815f7 to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment