expand, unexpand

expand tabs to spaces, and vice versa

expand [-t tab1,tab2,…,tabn] [file …]

unexpand [-a | -t tab1,tab2,…,tabn] [file …]

tabs changed into blanks and retain colums. Backspaces are preserved into the output and decrement the column count for tab calculations. useful for pre-processing files (before sorting, looking at specific columns, etc.) that contain tabs.

unexpand For numeric values, which are right justified, does not insert tabs!

unexpand puts tabs in.

-a unexpand
all series of spaces are replaced with tabs whenever they would compress the resultant file by replacing two or more characters.
default, only leading blanks and tabs are converted.
-t tab1[,tab2,…,tabn] Set tab stops at column positions.
If only a single number is given, tab stops are set that number of column positions apart
Default: 8.
 cat 0
xxx xx  xx  x
x   y   z   q

/Volumes/DATA/dgerman > hexdump -C 0
00000000  78 78 78 09 78 78 09 78  78 09 78 0a 78 09 79 09  |xxx.xx.xx.x.x.y.|
00000010  7a 09 71 0a 0a                                    |z.q..|


expand 0 >00
/Volumes/DATA/dgerman > cat 00
xxx     xx      xx      x
x       y       z       q

/Volumes/DATA/dgerman > hexdump -C 00
00000000  78 78 78 20 20 20 20 20  78 78 20 20 20 20 20 20  |xxx     xx      |
00000010  78 78 20 20 20 20 20 20  78 0a 78 20 20 20 20 20  |xx      x.x     |
00000020  20 20 79 20 20 20 20 20  20 20 7a 20 20 20 20 20  |  y       z     |
00000030  20 20 71 0a 0a                                    |  q..| 



unexpand 09 # has spaces. 
ID                                  Mac Address          Name    RSS °F     %   Z   Battery Movement 
                                                                                              Measurement # Samples Period  
fc75f7f98bef47529bab6cea054bb65a    F7:FA:74:4A:1E:1A    fc75    -56 72.1  44.5  1016 2.827   173   7380      800    16     11      
21eed0d15de149c998fdde95ae72bc63    D0:FD:6D:65:06:DC    21ee    -79 67.6  41.5   -44 2.932   147  11951      800     7     11      
da798d1d39354757aa6f294e73617493    D3:51:78:72:EC:0F    porchO  -79 62.7  74.4   968 2.935   -     2752      800     7      7       
3bb8010cedd74fc1b8f4cf693cf98bc1    C8:76:E5:96:B2:C3    3bb8    -89 68.8  36.6   220 2.626    41  30632      800    14      8       
d7eacacda5364f9fb92701178c19d17f    E4:D5:6D:EC:6E:29    d7ea    -83 65.7  35.3  -164 3.079    36  61927      800    19     18      
b3310fb7925044a38e93b0b1e404d55b    E4:9E:D5:86:E4:CE    b331    -75 55.0  53.7   128 2.647   156  61013      800    18      1       
ebc49873a5be4404b16b378a41d57ea3        -                furnace -88 79.2  25.5  1008 2.785     -   -         800    87     23      
f250d6b007b1404c994a01eabc0df913    F2:C0:C6:43:AD:03    f250    -94 38.1  27.2 -1036 2.395    93  20115        7 10299   5478        

unexpand 09|expand    # add tabs , then change to spaces still right justified
ID                                  Mac Address          Name    RSS °F     %   Z   Battery Movement 
                                                                                              Measurement # Samples Period  
fc75f7f98bef47529bab6cea054bb65a    F7:FA:74:4A:1E:1A    fc75    -56 72.1  44.5  1016 2.827   173   7380      800    16     11      
21eed0d15de149c998fdde95ae72bc63    D0:FD:6D:65:06:DC    21ee    -79 67.6  41.5   -44 2.932   147  11951      800     7     11      
da798d1d39354757aa6f294e73617493    D3:51:78:72:EC:0F    porchO  -79 62.7  74.4   968 2.935   -     2752      800     7      7       
3bb8010cedd74fc1b8f4cf693cf98bc1    C8:76:E5:96:B2:C3    3bb8    -89 68.8  36.6   220 2.626    41  30632      800    14      8       
d7eacacda5364f9fb92701178c19d17f    E4:D5:6D:EC:6E:29    d7ea    -83 65.7  35.3  -164 3.079    36  61927      800    19     18      
b3310fb7925044a38e93b0b1e404d55b    E4:9E:D5:86:E4:CE    b331    -75 55.0  53.7   128 2.647   156  61013      800    18      1       
ebc49873a5be4404b16b378a41d57ea3        -                furnace -88 79.2  25.5  1008 2.785     -   -         800    87     23      
f250d6b007b1404c994a01eabc0df913    F2:C0:C6:43:AD:03    f250    -94 38.1  27.2 -1036 2.395    93  20115        7 10299   5478