Skip to content

Instantly share code, notes, and snippets.

@prelongs
Created March 24, 2014 14:33
Show Gist options
  • Save prelongs/9741242 to your computer and use it in GitHub Desktop.
Save prelongs/9741242 to your computer and use it in GitHub Desktop.
replace multiple tab or space into one space
# 替换两个或多个空格为一个空格
sed 's/[ ][ ]*/ /g' file_name
# 替换两个或多个空格为分隔符:
sed 's/[ ][ ]*/:/g' file_name
# 如果空格与tab共存时用下面的命令进行替换
# 替换成空格
sed 's/[[:space:]][[:space:]]*/ /g' filename
# 替换成分隔符:
sed 's/[[:space:]][[:space:]]*/:/g' filename
# 一个使用的示例:提取jpeglib.h文件中的JPEG_LIB_VERSION的定义版本号字符串
# 文件中的该行为: #define JPEG_LIB_VERSION 62 /* version 62 */
# 结果为 62
sed -n '/#define JPEG_LIB_VERSION/s/[[:space:]][[:space:]]*/ /gp' jpeglib.h |cut -d " " -f 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment