Convert spaces to tabs (POSIX)
unexpand [-a] [-t tabsize] [file...]
Neutrino
The unexpand utility copies files or the standard input to the standard output, translating each group of eight spaces at the beginning of a line into a tab character. Any backspace characters in the input are copied to the output, and each causes the column position count for tab calculations to be decremented; the count is never decremented below zero.
For the file sourcecode, convert every run of eight spaces at the beginning of a line into a single tab:
unexpand sourcecode
Convert every run of two to eight spaces that precedes a tab stop into a single tab:
unexpand -a sourcecode
Convert every run of two to four spaces that precedes a tab stop into a single tab:
unexpand -a -t4 sourcecode