linux 空格 和 tab 的转换,使用 expand 和 unexpand

1)  expand 可以将 tab 转成空格

例如:foo.c 内容如下:

#include $
#include $
int main(){$
^Iprintf("hello\n");$
^Ireturn 0;$
}$

使用  expand -t 2 foo.c      #  1tab = 2 space

#include 
#include 
int main(){
  printf("hello\n");
  return 0;
}

2) unexpand 将 空格转成 tab

例如 hello.c 内容如下:

#include $
#include $
int main(){$
    printf("hello\n");$
    return 0;$
}$

使用  unexpand -t 4 hello.c      # 4 space = 1 tab

#include $
#include $
int main(){$
^Iprintf("hello\n");$
^Ireturn 0;$
}$





你可能感兴趣的:(命令行技巧)