awk, grep 'df -lah' into one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk, grep 'df -lah' into one line
# 1  
Old 05-12-2010
awk, grep 'df -lah' into one line

Hi Everyone,

Code:
[root@]# df -lah
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda7              75G   59G   13G  83% /
/proc                    0     0     0   -  /proc
sysfs                    0     0     0   -  /sys
devpts                   0     0     0   -  /dev/pts
/dev/sda5              99M   13M   82M  14% /boot
tmpfs                 500M     0  500M   0% /dev/shm
none                     0     0     0   -  /home/neotip/proc
none                     0     0     0   -  /proc/sys/fs/binfmt_misc

[root@]# df -akh | grep "/boot" | awk '{print $5}' | tr -d '\n'
14%

As you can see, i use grep, awk both and tr to remove the '\n', would like to seek one line awk to get the output of "14", without % also.

Thanks
# 2  
Old 05-12-2010
Code:
awk '$NF=="/boot"{sub(/%/,"",$5);print $5}' infile
14

# 3  
Old 05-12-2010
Quote:
Originally Posted by zaxxon
Code:
awk '$NF=="/boot"{sub(/%/,"",$5);print $5}' infile
14

Thanks, finally i use
Code:
df -lah | awk '$NF=="/boot"{sub(/%/,"",$5);print $5}' - | tr -d '\n'

# 4  
Old 05-12-2010
or,

Code:
df -lah | awk '$NF=="/boot"{print int($5)}'

just curious, why do you want to remove the newline?

if you are using this value as a variable, you can do that without that.
Code:
usage=$(df -lah | awk '$NF=="/boot"{print int($5)}')

use nawk or usr/xpg4/bin/awk on solaris
# 5  
Old 05-12-2010
Quote:
Originally Posted by anchal_khare
or,

Code:
df -lah | awk '$NF=="/boot"{print int($5)}'

just curious, why do you want to remove the newline?

if you are using this value as a variable, you can do that without that.
Code:
usage=$(df -lah | awk '$NF=="/boot"{print int($5)}')

use nawk or usr/xpg4/bin/awk on solaris

Thanks, the reason i want to remove % and '\n', bec i want to do the comparsion, like when one partition is over 80 percent, i can do else.
Like my perl file
Code:
next if (`ssh 1.1.1.1 'df -lah' | awk '\$NF=="/boot"{print int(\$5)}' | tr -d '\n'` < 90);

Thanks for your code.

Last edited by jimmy_y; 05-12-2010 at 11:33 AM..
# 6  
Old 05-12-2010
No % and no newline:
Code:
awk '$6=="/boot" {printf($5+0)}'

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk grep, that will only get the line with more characters.

Is there a command for sed and awk that will only sort the line with more characters? #cat file 123 12345 12 asdgjljhhho bac ss Output: asdgjljhhho #cat file2 11.2 12345.00 21.222 12345678.10 (2 Replies)
Discussion started by: invinzin21
2 Replies

2. Shell Programming and Scripting

awk or sed or grep filter a line and/or between strings

Hi, I have multiple files on a directory with the following content: blahblah blahblah hostname server1 blahblah blahblah ---BEGIN--- aaa bbb ccc ddd ---END--- blahblah blahblah blahblah I would like to filter all the files with awk or sed or something else so I can get below... (6 Replies)
Discussion started by: bayupw
6 Replies

3. Shell Programming and Scripting

Grep echo awk print all output on one line

Hello, I've been trying to find the answer to this with Google and trying to browse the forums, but I haven't been able to come up with anything. If this has already been answered, please link me to the thread as I can't find it. I've been asked to write a script that pulls a list of our CPE... (51 Replies)
Discussion started by: rwalker
51 Replies

4. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

5. Shell Programming and Scripting

Use less pipe for grep or awk sed to print the line not include xx yy zz

cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies

6. Shell Programming and Scripting

AWK-grep from line number to the end of file

Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed. Say I want to print all occurrences of red starting at line 3 to the end of file. EXAMPLE FILE: red green red red... (1 Reply)
Discussion started by: thibodc
1 Replies

7. Shell Programming and Scripting

Grep to isolate a text file line and Awk to select a word?

I am looking at using grep to locate the line in the text file and them use awk to select a word or words out of it. I know awk needs -v to allow a variable to be used, but also needs -F to allow the break up of the sentence and allow the location of separate variables. $line = grep "1:" File |... (8 Replies)
Discussion started by: Ironguru
8 Replies

8. UNIX for Dummies Questions & Answers

Grep /Awk letters X - X in every line and print it as a mac address

hey i m kinda new to this so i will appreciate any help , i have this list of values: pwwn = 0x50012482009cd7a7 nwwn=0x50012482009cd7a6 port_id = 0x280200 pwwn = 0x5001248201bcd7a7 nwwn=0x5001248201bcd7a6 port_id = 0x280300 pwwn = 0x50012482009c51ad nwwn=0x50012482009c51ac port_id =... (4 Replies)
Discussion started by: boaz733
4 Replies

9. Shell Programming and Scripting

Problems with Sed/awk/grep and line endings

Hello I have created the following script, which is designed to manipulate a text document: #!/bin/sh # Get 3 lines, (last of which is "Quantity"); adjust order; put all three on one line with tabs. FILENAME=~/Desktop/email.txt LIST=$(grep -B2 "Quantity" ${FILENAME} |awk 'BEGIN { FS = "\n"; RS... (6 Replies)
Discussion started by: benwiggy
6 Replies

10. Shell Programming and Scripting

Isolating a specified line - awk grep or somthing else?

I'm trying to isolate attached hard drives that auto-mount to /media so that I can use them as variables in a bash script... so far I'm here: variable=$(ls /media | grep -v cdrom ) This lists all the connected drives, each on it's own line and doesn't list anything I don't want (cdrom... (2 Replies)
Discussion started by: Starcast
2 Replies
Login or Register to Ask a Question