In a text that part of the characters are in Hebrew, how to delete spaces before and after a comma using regex?

Viewed 92

I need to remove the spaces that are before and after the commas in a csv file that contains Hebrew characters. The solution to this problem would be quite simple when the csv file contains only English characters using sed and regex. But in my case, I can't get the desired result because of the Hebrew characters.

example of a line in the csv file: file1, file2, קובץ 3, קובץ 4, קובץ 5, סוף

this command works only when all characters are in english: sed 's/(\s+,)?(,\s+)?/,/' -i file_path

1 Answers

You may use

sed 's/[[:space:]]*,[[:space:]]*/,/g' file > otufile
sed -i 's/\s*,\s*/,/g' file

See online demo

Details

  • [[:space:]]*,[[:space:]]* - any 0 or more whitespace, comma, any 0 or more whitespace
  • g - global flag, matches and replaces all occurrences in the string.
Related