2

I have a bunch of texts files although they all have spaces at the beginning of lines

e.g.

 testing 123
 download
 upload

would be

testing 123
download
upload

Preferably using a utility such as grep etc.

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
Jay
  • 53
  • 1
  • 1
  • 5
  • The answer is going to be different for linux and windows. Can you remove the tag for one of them (unless you happened to need the answer for both OS's) – matzahboy Jun 03 '11 at 13:20
  • Do you want to do this in place (ie. overwriting the original files) or into new files (so you keep the originals)? – Richard Jun 03 '11 at 13:21
  • @matzahboy that depends what you use, my perl solution is cross platform. – Raoul Jun 03 '11 at 13:21
  • @Raoul good point. I was thinking shell script which isn't cross platform – matzahboy Jun 03 '11 at 22:08

3 Answers3

1
sed -i -e's/^\s*//' yourfilenamehere
Benedikt Waldvogel
  • 12,406
  • 8
  • 49
  • 61
1

You can use sed

sed 's/^ *//' file

This should work with Linux and your GNUWin Toolkit.

echo "     Line starting with spaces" | sed 's/^[ \t]*//'
keyboardP
  • 68,824
  • 13
  • 156
  • 205
0
perl -pi -e 's/^\s+//' yourfilenamehere
Raoul
  • 3,849
  • 3
  • 24
  • 30