0

we want to delete all "," separator ONLY after the last string ( any string )

  echo "df true , , ," |  sed 's/,,*$//'
  df ,true , ,

but syntax delete only one ","

what need to fix in my syntax so all "," after the last string will be deleted ?

expected output:

df ,true

example1

echo "dejd ,dede,dede 73hygys626^%%,J , ,  ,," | sed ......

expected output

dejd ,dede,dede 73hygys626^%%,J

example2

echo "lfr  r.,r,ff rger.ref done ,,, , "

expected output

lfr  r.,r,ff rger.ref done
  • Try: sed 's/,//g – pfnuesel Mar 15 '18 at 10:14
  • 1
    But this is probably not what you want. It's not clear to me from your question. – pfnuesel Mar 15 '18 at 10:14
  • the given sample has spaces between , but code attempted doesn't use spaces... please clarify that – Sundeep Mar 15 '18 at 10:15
  • this syntax deleted all "," in line , what we want is to delete the "," only after the last string – yael Mar 15 '18 at 10:16
  • see my update , hope its help – yael Mar 15 '18 at 10:18
5
sed 's/[ ,]*$//'

Doesn't this do what you want?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.