2011-06-03 53 views
1

我有一堆文本在线条在一个文本文件中删除前导空格

例如的开头的文件,虽然它们都有空间

testing 123 
download 
upload 

将是

testing 123 
download 
upload 

优选地使用工具如grep的等

+0

对于linux和windows,答案会有所不同。你能删除它们中的一个标签吗(除非你碰巧需要两个操作系统的答案) – matzahboy 2011-06-03 13:20:15

+0

你是否想要做到这一点(即覆盖原始文件)或新文件(所以你保留原件)? – Richard 2011-06-03 13:21:02

+0

@matzahboy取决于你使用的是什么,我的perl解决方案是跨平台的。 – Raoul 2011-06-03 13:21:27

回答

0
sed -i -e's/^\s*//' yourfilenamehere 
0
perl -pi -e 's/^\s+//' yourfilenamehere 
+0

对不起,perl对我来说是尴尬的,因为我需要将它安装在几百台电脑的 – Jay 2011-06-03 13:21:37

+0

@Jay你的文章被标记为linux,> 99%装有Perl。 – Raoul 2011-06-03 13:22:10

+0

那是正确的,我有GNUWin工具包可用 – Jay 2011-06-03 13:23:34

0

可以使用sed

sed 's/^ *//' file 

这应该适用于Linux和GNUWin Toolkit。

echo "  Line starting with spaces" | sed 's/^[ \t]*//' 
相关问题