Solved

Linux: remove last comma

Posted on 2013-11-15
3
302 Views
Last Modified: 2013-11-15
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

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 39651139
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
 
LVL 16

Author Comment

by:hankknight
ID: 39651145
That removes ALL commas.  I need valid JSON so I only want the very last comma to be removed.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39651188
df  | awk '! /[Ff]ilesystem/ {sub("%","",$5); print "\""$1"\":"$5"," }'| sed '$s/,$//'
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question