heroZero
heroZero

Reputation: 173

Remove specific white spaces from txt file

I have a large txt file with two columns, the two columns are separated by a lot of white space:

123467,       And the second part here

To remove the white space between the columns I used

sed -e "s/ /,/g" < a.txt

However it also removed the spaces between words in the second column

And the second part here

How can I just remove the spaces between columns without effecting the words in second column?

Upvotes: 0

Views: 163

Answers (3)

Ed Morton
Ed Morton

Reputation: 203684

$ sed 's/  *//' file
123467,And the second part here

Upvotes: 1

William Pursell
William Pursell

Reputation: 212268

Since you're thinking of the file as being columns separated by commas, it makes sense to use a tool that treats the input as columns separated by commas:

awk '$1=$1' OFS=, FS=', *' input

Upvotes: 0

NoDataFound
NoDataFound

Reputation: 11959

You could do this:

sed -E -e 's@, +@,@'

This would remove space after a ,. You should also not use g as it will try to match all pattern in the line.

Upvotes: 2

Related Questions