How to extract the value of "%" using scripting?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract the value of "%" using scripting?
# 1  
Old 06-10-2010
Question How to extract the value of "%" using scripting?

Hi Gurus,

I'm using HPUX system (unix based system).

When I execute "bdf" command, it will display the following information (sample data only):

Code:
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol4 2097152 1623080 470400 78% /tmp
/dev/vgsap/oracle 262144 6299 239910 3% /oracle
...<blank space>...10485760 4859180 5274921 48% /oracle/stage/102_64
...<blank space>...262144 117369 135731 46% /oracle/client

My question is, how would I be able to extract the percentage value out?

Desired output:
Code:
78%
3%
48%
46%

Please take note that somehow there is an empty space at the front in the last 2 lines. Space is represented as <blank space> as shown above.

Would appreciate for any of your help and advice.

Thank you.



Regards,
Peter

Last edited by vgersh99; 06-10-2010 at 01:54 PM.. Reason: code tags, please!
# 2  
Old 06-10-2010
Code:
sed -n "s/.* \([0-9]\{1,\}%\).*/\1/p" file

# 3  
Old 06-10-2010
Code:
nawk 'FNR>1 {print $(NF-1)}' myFile

# 4  
Old 06-14-2010
Hi All,

Thank you for all of your responses and advices.

With your help, I've managed to extract out the percentage.

Here is my current output format.
Code:
/tmp 78% 
/oracle 3% 
/oracle/stage/102_64 48% 
/oracle/client 46%

However, how would I be to format the output into this below format?

Code:
/tmp............................78% 
/oracle.........................3% 
/oracle/stage/102_64.....48% 
/oracle/client................46%

Once again, thanks for your help.

PS:
Please ignore the dotting (..............) as it's used for format alignment only.


Regards,
Peter

Last edited by vgersh99; 06-14-2010 at 06:33 AM.. Reason: code tags, please!
# 5  
Old 06-14-2010
Try:
Code:
bdf|awk 'NR>1{printf "%28-s%3s\n",$NF,$(NF-1)}'

# 6  
Old 06-14-2010
Hi,

Thank you for your response.

I've tried your command, but it does not work as sometimes the path can be quite long and it's carried to the next line.

Here is the output:

Code:
bdf|awk 'NR>1{printf "%28-s%3s\n",$NF,$(NF-1)}'
/dev/vgsap/orastage         /dev/vgsap/orastage
/oracle/stage/102_64        48%
/dev/vgsap/oraclient        /dev/vgsap/oraclient
/oracle/client              46%

Please kindly advice.

Thanks.


Regards,
Peter

Moderator's Comments:
Mod Comment I kindly advise you to use code tags. Thank you Smilie

Last edited by Scott; 06-14-2010 at 11:32 AM..
# 7  
Old 06-14-2010
How about:
Code:
bdf | awk 'NR>1&&NF>1{printf "%32-s%3s\n",$NF,$(NF-1)}'

This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Solaris

The slices "usr", "opt", "tmp" disappeared!!! Help please.

The system don't boot. on the screen appears following: press enter to maintenance (or type CTRL-D to continue)...I checked with format command. ... the slices "0-root","1-swap","2-backup" exist. ...the slises "3-var","6-usr" -unassigned. :( (16 Replies)
Discussion started by: wolfgang
16 Replies

6. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question