Solved

Linux: remove last comma

Posted on 2013-11-15
3
298 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Xymon customize http timeout 2 84
nagios alerts 3 44
CentOS create a user with predefined MD5 Hashed password 17 84
Why isn't object file created? 6 57
Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

805 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