unexpand 命令用於將給定檔案中的空白字元 (space) 轉換為製表符 (TAB), 並把轉換結果顯示在標準輸出裝置 (顯示終端). 功能與 expand 相反.
語法:
unexpand [options]
引數:
-a/-all : 轉換檔案中所有空白字元;
–first-only : 僅轉換開頭的空白字元;
-t : 指定 TAB 所代表的 n 個字元數, 預設 n 值為 8;
 
這裏我想通過將 expand 將 tab 鍵轉換為空格, 儲存到 03.txt 檔案中, 如下:
#grep “^MANPATH” /etc/man.config | head -n 3 |expand -t 6  > 03.txt
# cat -A 03.txt
MANPATH     /usr/man$
MANPATH     /usr/share/man$
MANPATH     /usr/local/man$
接下來, 我以 2 個空格為一個單位轉換為一個 tab 鍵, 如下:
# cat  03.txt | unexpand -t 2 | cat -A
MANPATH^I^I^I/usr/man$
MANPATH^I^I^I/usr/share/man$
MANPATH^I^I^I/usr/local/man$
原來有 6 個空格, 所以這裏顯示出三個^I.