git - 'git stripspace' 如何实际工作(文档无用)
问题描述
我正在尝试运行git stripspace
,但文档毫无价值。
似乎将其作为输入git stripspaces
并stdin
写入stdout
但:
% git stripspace < myfile.txt > myfile.txt
删除了里面的所有文字myfile.txt
我希望文档提供了一个调用示例。有人有吗?
解决方案
sponge
是解决这个问题的工具。它首先“吸收”所有通过管道传输的数据,然后将其写入指定的文件。它是moreutils
软件包的一部分 - 在 Ubuntu 上安装它sudo apt install moreutils
,
这是一个使用文件的示例spacetest.txt
- 该awk
命令用于帮助可视化文件中存在的尾随空格:
# print the file spacetest.txt with '%' appended to each line-end to show trailing spaces
~/temp/stripspace-test$ awk '{ print $0 "%" }' spacetest.txt
%
%
line 1 has a space at the end %
line 2 has 2 spaces at the end %
line 3 has 3 spaces at the end %
%
the next line has 4 spaces%
%
three blank lines follow this one%
%
%
%
# 'redirect' from and to spacetest.txt using `sponge` as a go-between
~/temp/stripspace-test$ git stripspace < spacetest.txt | sponge spacetest.txt
# print the file spacetest.txt again to demonstrate everything is as expected
~/temp/stripspace-test$ awk '{ print $0 "%" }' spacetest.txt
line 1 has a space at the end%
line 2 has 2 spaces at the end%
line 3 has 3 spaces at the end%
%
the next line has 4 spaces%
%
three blank lines follow this one%
推荐阅读
- python - Flask App 使用错误的 Python 解释器 - 需要知道如何“编译”mod_wsgi 以使用特定的 Python 版本
- ruby-on-rails - Rails 5无法存储在数据库中
- pandas - Python读取压缩文件夹中子文件夹内的csv文件
- r - 剧情:如何改变休息时间?
- android - 我怎样才能reslove方法'toMap'在null上被调用?
- java - JavaSWT 应用程序在 Eclipse 中工作但在终端中不工作
- excel - 用另一个工作表中的数据动态填充下一个空行
- javascript - 使用 formik 从字段名称列表中显示输入字段
- opencv - 如何从图像中提取嘈杂的连接组件?
- android - Kotlin 中的 DialogFragment.onDismiss() 空指针异常