0

I am new in bash and would like to know best way to remove those white spaces which are available after each comma in string. For e.g. I have following input string :

abc, xyz, cdf axy bnz cnm 

Resultant string should be :

abc,xyz,cdf axy bnz cnm 

2 Answers 2

1

You can use sed for this

$ sed -E 's/, +/,/g' input_file abc,xyz,cdf axy bnz cnm 
Sign up to request clarification or add additional context in comments.

1 Comment

sed 's/, */,/g'
1

Turn on the extglob option and do it with parameter expansion pattern replacement:

#!/usr/bin/env bash str="abc, xyz, cdf axy bnz cnm" shopt -s extglob printf "%s\n" "${str//,+([[:space:]])/,}" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.