Solved

Linux: Get rid of % when using grep and awk

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IP 10.0.1.2 / 255.0.0.0 61 79
Replacing multiple embedded commas in a CSV file with sed 10 26
Understanding ping command in Ubuntu 5 33
RPM creation 6 21
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…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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

749 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