Solved

Linux: Get rid of % when using grep and awk

Posted on 2013-11-15
3
408 Views
Last Modified: 2013-11-15
I use this to trim the % from the end of a string:
x="10%"
echo ${x%\%}

Open in new window


I use this to return results from df in JSON format:
df |grep -iv "filesystem" | awk '{print"\""$1"\":"$5"," }'

Open in new window


How can these two concepts be combined?  I want to remove % from the JSON results.
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
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39651013
No need for "grep".

df | awk '! /[Ff]ilesystem/ {sub("%","",$5); print"\""$1"\":"$5"," }'

"sub" means "substitute". All we have to do is replacing the "%" sign with the empty string "".
wmp
0
 
LVL 20

Expert Comment

by:carlmd
ID: 39651015
I don't see a % sign in the result of

df |grep -iv "filesystem" | awk '{print"\""$1"\":"$5"," }'

Can you post an example of what you see?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39651029
I think hankknight's "df" behaves like "df -P" (POSIX format, where the 5th column is "%Used").
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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

623 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