tags:

views:

115

answers:

3

I need to remove the first three occurrences of space per line in a text file.

I have tried the following:

sed 's/ //3'

This only removes the third occurrence.

sed 's/ //3g'

This leaves the first three occurrences of space alone and removes all of the following, this is the exactly the opposite of what i want.

+5  A: 
sed -e 's/ //' -e 's/ //' -e 's/ //'
Tim
`'s/ //;s/ //;s/ //'` I saved 10 chars!
LiraNuna
I can't believe that i did not think about this solution.
ytu903
A: 

sed 's/ \{1,3\}//' < file.txt

Bob Aman
Only gets the first one for me... you sure?
Deverill
This only works if there are 3 consecutive spaces.
EmFi
Useless use of `cat`
Dennis Williamson
Oooooooh. Actually, 3 consecutive spaces was what I thought he was after, but yeah.
Bob Aman
+1  A: 
Beta
What's the redirection for?
Dennis Williamson
no need redirection....
ghostdog74
You're right. Force of habit.
Beta