?
Solved

Linux: remove last comma

Posted on 2013-11-15
3
Medium Priority
?
304 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 2000 total points
ID: 39651188
df  | awk '! /[Ff]ilesystem/ {sub("%","",$5); print "\""$1"\":"$5"," }'| sed '$s/,$//'
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

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.…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

719 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