Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Substr with % - extract numbers only Post 303035751 by danielshell on Sunday 2nd of June 2019 05:09:50 AM
Old 06-02-2019
Substr with % - extract numbers only

Code:
 # cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.5 (Maipo)

I have this script that will monitor filesystems and send me e-amil alerts.

Code:
#! /bin/ksh 
DIST_LIST=monitor@...com

WORKDIR=/home/monitor
WARNLEVEL=90

MAIL_SUBJ="filesystems monitor on "$(hostname)

ALERT_ADMIN () { mail -s "${MAIL_SUBJ}"  $DIST_LIST  << EOF
Filesystem $fsname has reached $sz% of its capacity.
EOF
return
}

cd . > $WORKDIR/freespace.lst
exec 8< $WORKDIR/freespace.lst

df -k | grep -v -i Filesystem | grep -v ":" | awk '{print $5}' |  grep -v "%" | grep -v proc > $WORKDIR/freespace.lst

if [ -f $WORKDIR/freespace.lst ]
then
 while read -u8 fsname sz ;
   do
   if [[ $sz -gt $WARNLEVEL ]]
     then  
        ALERT_ADMIN
    fi 
done 
fi

rm $WORKDIR/freespace.lst

However, the ksh gets % as well.

Code:
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/vg00-rootlv            10G  1.9G  8.2G  19% /
devtmpfs                          189G     0  189G   0% /dev
tmpfs                             189G   39M  189G   1% /dev/shm
tmpfs                             189G  380M  188G   1% /run
tmpfs                             189G     0  189G   0% /sys/fs/cgroup
/dev/mapper/vg00-usrlv            5.0G  2.4G  2.7G  47% /usr
/dev/mapper/vg00-tmplv            8.0G   41M  8.0G   1% /tmp
/dev/mapper/vg00-homelv           4.0G   45M  4.0G   2% /home
/dev/mapper/vg00-usrlocallv       2.0G  674M  1.4G  34% /usr/local
/dev/mapper/vg00-optlv            8.0G  563M  7.5G   7% /opt
/dev/mapper/vg00-optstagelv        40G   18G   23G  44% /opt/stage
/dev/emcpowerg2                   976M  262M  648M  29% /boot
/dev/emcpowerg1                   200M  9.8M  191M   5% /boot/efi
/dev/mapper/vg00-varlv            4.0G  1.3G  2.8G  31% /var

Code:
19%
0%
1%
1%
0%
47%
1%
2%
34%
7%
44%
29%
5%
31%
31%
1%
4%
2%
11%

Please let me know how to grep numbers only..
I have tried substr($5,1,2) substr($1,1,2), but I am misssing something here.

Thank you!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract numbers from a string and store in variables

Hi All, Is it possible in Unix shell script to extract numbers from a string containing ".", such as; 5.2.314 And store in variables so; var1 = 5 var2 = 2 var3 = 314 Thanks in advance for any help anyone can provide dave (6 Replies)
Discussion started by: davewg
6 Replies

2. Shell Programming and Scripting

Extract numbers below words with awk

Hi all, Please some help over here. I have a Sales.txt file containing info in blocks for every sold product in the pattern showed below (only for 2 products). NEW BLOCK SALE DATA PRODUCT SERIAL 79833269999 146701011945004 .Some other data .Some... (17 Replies)
Discussion started by: cgkmal
17 Replies

3. Shell Programming and Scripting

extract numbers from a word

Hi ppl, I am a bit lost on this...can some one assist. I know this can be down with awk or sed, but i cant get the exact syntax right. I need to only extract the numbers from a signle word ( eg abcd.123.xyz ) How can i extract 123 only ? Thanks (14 Replies)
Discussion started by: systemali
14 Replies

4. Shell Programming and Scripting

BASH. Need to extract some numbers and take the average

Hey all, I ran some simulations, of which the output is 100s of files. I've used grep to extract the vital information needed from the files. This has made my task somewhat easier. But I still need to perform some mathematical calculations (average and geometrical average) on the results of the... (9 Replies)
Discussion started by: slackjack
9 Replies

5. UNIX for Dummies Questions & Answers

Extract numbers from .txt file

I need to extract all the p-value numbers and the rho numbers from a .txt file and write them as coma separated values in a new file. Ideally I would get two files in the end, one for p- values and one for rho. Any suggestions? I appreciate your help!!! The .txt file looks essentially like this... (5 Replies)
Discussion started by: eggali
5 Replies

6. Shell Programming and Scripting

awk extract certain digits from file with index substr

I would like to extract a digit from $0 starting 2,30 to 3,99 or 2.30 to 3.99 Can somebody fix this? awk --re-interval '{if($0 ~ /{1}{2}/) {print FILENAME, substr($0,index($0,/{1}{2}/) , 4)}}'input abcdefg sdlfkj 3,29 g. lasdfj alsdfjasl 2.86 gr. slkjds sldkd lskdjfsl sdfkj kdjlksj 3,34 g... (4 Replies)
Discussion started by: sdf
4 Replies

7. UNIX for Dummies Questions & Answers

Extract Numbers from a log file

Hi, I am trying to grep/extract the number list from this log file, can I get some help on this. I can grep the word 'href' to see the numbers, but it is resulting with the complete line. Content of my file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head>... (4 Replies)
Discussion started by: Sajjadmehdi
4 Replies

8. Shell Programming and Scripting

Extract numbers from file name-how to ?

Hello friends,I am new to Unix programming. how do I achieve the following in Unix shell script (I am running ksh on AIX) extract the number from name of file? My file format is like "LongFileName-1234.020614-221030.txt" now I want to extract value which is between (-) hyphen and (.) dot... (4 Replies)
Discussion started by: f150
4 Replies

9. Shell Programming and Scripting

How to use substr to extract character between two semicolon?

Dear folks Hello I have a data set which one of the column of this data set are string and I want to extract numbers which is between two ":". However, I know the substr command which will do this operation but my problem is the numbers between two ":" have different digits. this will make my... (11 Replies)
Discussion started by: sajmar
11 Replies

10. Shell Programming and Scripting

Substr/Instr in shell script or extract part of text

Hi, I need to extract part of a text to two variables text is "PL/SQL procedure successfully completed. ERROR ----------------------------------------------------------------- Test Error Message PLUSVAR ---------- 1" I want "Test Error Message" in one variable and "1" in another variable.... (11 Replies)
Discussion started by: vedavrath
11 Replies
MU-EXTRACT(1)                                                 General Commands Manual                                                MU-EXTRACT(1)

NAME
mu_extract - display and save message parts (attachments), and open them with other tools. SYNOPSIS
mu extract [options] <file> mu extract [options] <file> <pattern> DESCRIPTION
mu extact is the mu sub-command for extracting MIME-parts (e.g., attachments) from mail messages. It works on message files, and does not require the message to be indexed in the database. For attachments, the file name used when saving it, is the name of the attachment in the message. If there is no such name, or when saving non-attachment MIME-parts, a name is derived from the message-id of the message. If you specify a pattern (a case-insensitive regular expression) as the second argument, all attachments with filenames matching that pat- tern will be extracted. The regular expressions are Perl-compatible (as per the PCRE-library). Without any options, mu extract simply outputs the list of leaf MIME-parts in the message. Only 'leaf' MIME-parts (including RFC822 attach- ments) are considered, multipart/* etc. are ignored. OPTIONS
-a, --save-attachments save all MIME-parts that look like attachments. --save-all save all non-multipart MIME-parts. --parts=<parts> only consider the following numbered parts (comma-separated list).The numbers for the parts can be seen from running mu extract without any options but only the message file. --target-dir=<dir> save the parts in the target directory rather than the current working directory. --overwrite overwrite existing files with the same name; by default overwriting is not allowed. --play Try to 'play' (open) the attachment with the default application for the particular file type. On MacOS, this uses the open program, on other platforms is uses xdg-open. You can choose a different program by setting the MU_PLAY_PROGRAM environment variable. EXAMPLES
To display information about all the MIME-parts in a message file: $ mu extract msgfile To extract MIME-part 3 and 4 from this message, overwriting existing files with the same name: $ mu extract --parts=3,4 --overwrite msgfile To extract all files ending in '.jpg' (case-insensitive): $ mu extract msgfile '.*.jpg' To extract an mp3-file, and play it in the the default mp3-playing application. $ mu extract --play msgfile 'whoopsididitagain.mp3' BUGS
Please report bugs if you find them: http://code.google.com/p/mu0/issues/list AUTHOR
Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> SEE ALSO
mu(1) User Manuals February 2012 MU-EXTRACT(1)
All times are GMT -4. The time now is 02:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy