如何在给定的文本文件中将linux中的空格替换为制表符?
发布于 2009-09-14 22:00:02
我认为您可以尝试使用awk
awk -v OFS="\t" '$1=$1' file1
如果您愿意,也可以选择SED
sed 's/[:blank:]+/,/g' thefile.txt > the_modified_copy.txt
或者甚至是树
tr -s '\t' < thefile.txt | tr '\t' ' ' > the_modified_copy.txt
或者是Sam Bisbee建议的tr解决方案的简化版本
tr ' ' \\t < someFile > someFile
发布于 2017-01-31 22:10:34
下载并运行以下脚本,以递归方式将软制表符转换为纯文本文件中的硬制表符。
从包含纯文本文件的文件夹中放置并执行脚本。
#!/bin/bash
find . -type f -and -not -path './.git/*' -exec grep -Iq . {} \; -and -print | while read -r file; do {
echo "Converting... "$file"";
data=$(unexpand --first-only -t 4 "$file");
rm "$file";
echo "$data" > "$file";
}; done;
发布于 2015-11-04 17:24:27
将当前目录下的每个.js文件转换为制表符的示例命令(仅转换前导空格):
find . -name "*.js" -exec bash -c 'unexpand -t 4 --first-only "$0" > /tmp/totabbuff && mv /tmp/totabbuff "$0"' {} \;
https://stackoverflow.com/questions/1424126
复制相似问题