Linux: remove last comma

The very last item should not end in a comma:
df | awk '! /[Ff]ilesystem/ {sub("%","",$5); print"\""$1"\":"$5"," }'| sed 's/^,*//g'

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
 
woolmilkporcCommented:
df  | awk '! /[Ff]ilesystem/ {sub("%","",$5); print "\""$1"\":"$5"," }'| sed '$s/,$//'
0
 
mankowitzCommented:
I can't be totally sure what you are doing, but if you are using

sed 's/^,*//g'

that will remove a leading comma, but not a trailing comma. Try

sed 's/,*$//g'
0
 
hankknightAuthor Commented:
That removes ALL commas.  I need valid JSON so I only want the very last comma to be removed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.