2011-06-03 71 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]*//'