awk & remove other than numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk & remove other than numbers
# 1  
Old 07-22-2011
awk & remove other than numbers

HTML Code:
lsps -s | awk '{print $1}'|tail -1    
71680 MB
lsps -s | awk '{print $2}'|tail -1
2%
vmstat |grep lcpu |awk '{print $3}'
lcpu=8
I need to removt the MB % lcpu= from the outputs so they can show as

71680
2
8

respectively.

Please advise.

Thank you so much,
# 2  
Old 07-22-2011
Tools AWK

Try this Code,
Code:
nawk '{while(sub(/[a-zA-Z=%]/,"")){}print}' file_name

you can change as many special character do you want.

Cheers,
RangaSmilie

Last edited by Franklin52; 07-22-2011 at 02:19 PM.. Reason: Please use code tags for data and code samples, thank you
This User Gave Thanks to rangarasan For This Post:
# 3  
Old 07-22-2011
Quote:
Originally Posted by rangarasan
Try this Code,

nawk '{while(sub(/[a-zA-Z=%]/,"")){}print}' file_name

you can change as many special character do you want.

Cheers,
RangaSmilie
why exactly do you need a while and a sub?
Won't gsub be sufficient?
also:
Code:
echo '2%' | nawk '{print $0+0}'
echo '2%' | tr -cd '[0-9]'

This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 07-22-2011
Tools AWK

Quote:
Originally Posted by vgersh99
why exactly do you need a while and a sub?
Won't gsub be sufficient?
also:
Code:
echo '2%' | nawk '{print $0+0}'
echo '2%' | tr -cd '[0-9]'

why not, you can use this tooSmilie

Code:
nawk '{gsub(/[a-zA-Z=%]/,"");print}' file_name


Cheers,
Ranga Smilie

Last edited by radoulov; 07-22-2011 at 11:40 AM.. Reason: Code tags, please!
This User Gave Thanks to rangarasan For This Post:
# 5  
Old 07-22-2011
It works fine for lsps -s output.

but, it is a bit tricky for vmstat |grep lcpu

The output of
PHP Code:
vmstat |grep lcpu 
is
PHP Code:
System configurationlcpu=8 mem=20480MB 
How do you get 8 (which is lcpu value)?

Thank you so much.
# 6  
Old 07-22-2011
Code:
vmstat | nawk -F= '/lcpu/ {print $2+0}'

This User Gave Thanks to vgersh99 For This Post:
# 7  
Old 07-22-2011
Thank you so much. It works perfect!

---------- Post updated at 11:12 AM ---------- Previous update was at 11:01 AM ----------

Sorry, one more thing to ask!

PHP Code:
System configurationlcpu=8 mem=20480MB 
for the mem,
I tried,
PHP Code:
vmstat nawk -F'/mem/ {print $3+0}' 
PHP Code:
20480

but it gives extra line with 0.

How do you get only 20480?

Thank you so much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove numbers

how to remove all numbers from this.Using sed command 1. abcd123 2. 312jjs33 (17 Replies)
Discussion started by: rafa_fed2
17 Replies

2. Shell Programming and Scripting

Number of elements, average value, min & max from a list of numbers using awk

Hi all, I have a list of numbers. I need an awk command to find out the numbers of elements (number of numbers, sort to speak), the average value the min and max value. Reading the list only once, with awk. Any ideas? Thanks! (5 Replies)
Discussion started by: black_fender
5 Replies

3. Shell Programming and Scripting

sed&awk: replace lines with counting numbers

Dear board, (I am trying to post this the 3rd time, seems there's some conflicts with my firefox with this forum, now use IE) ------ yes, I have searched the forum, but seems my ? is too complicated. ------------origianl file --------------- \storage\qweq\ertert\ertert\3452\&234\test.rec... (4 Replies)
Discussion started by: oUo
4 Replies

4. Shell Programming and Scripting

Remove Numbers from file

I have a file that has some text that looks like this Some Text 1. More text 2. Different text Final Text I would like the remove the lines of text that start with the numbers. Some Text Final Text I have tried to use cat file.txt | grep -Ev 1. >... (9 Replies)
Discussion started by: icculus99
9 Replies

5. Shell Programming and Scripting

remove the numbers

How can I remove the numeric (1,2,3,4,5,etc.) in front of each line? The file look like this.. 1CREATE OR REPLACE pROD (p_sc_id number, 2 p_snap_id number , p_sid number, p_halt varchar2 default 'N', p_a_nm varchar2 ) 3 as 4 v_rtn number; 5 6 v_rtn... (3 Replies)
Discussion started by: Beginer0705
3 Replies

6. Shell Programming and Scripting

regex to remove text before&&after comma chars

Hi, all: I have a question about "cleaning up" a huge file with regular expression(s) and sed: The init file goes like this: block1,blah-blah-blah-blah,numseries1,numseries2,numseries3,numseries4 block2,blah-blah-blah-blah-blah,numseries,numseries2,numseries3,numseries4 ...... (3 Replies)
Discussion started by: yomaya
3 Replies

7. Shell Programming and Scripting

How to remove numbers from filename

Hi all, Can I edit this script: find . -type f | while read i;do && mv "$i" "${i//abc/}" ;done so that it will not only take out abc from the filename but also take out any numbers that might be in the filename as well. An example would be, Input: filename abc 2009.mov Output:... (7 Replies)
Discussion started by: Monkey Dean
7 Replies

8. Shell Programming and Scripting

Remove lines, Sorted with Time based columns using AWK & SORT

Hi having a file as follows MediaErr.log 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:12:16 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:22:47 84 Server1 Policy1 Schedule1 master1 05/08/2008 03:41:26 84 Server1 Policy1 ... (1 Reply)
Discussion started by: karthikn7974
1 Replies

9. Shell Programming and Scripting

How to remove all lines with something other than numbers

Hi, How would I get rid of lines having something else than numbers (such as tabs,white space, special characters, empty line, letters). So I have big file with numers as follows: 12345678901 23456789012 32343678901 42345638901 52345678901 and I sometimes the file might contain some... (2 Replies)
Discussion started by: Juha
2 Replies

10. Shell Programming and Scripting

Numbers & stack commands

Hi everyone, Sorry I keep asking these stupid perl questions here. They're not any sort of assignment or anything like that, I'm just browsing through the book "Learning Perl" and I'm finding that I can do some of their practice exercises just fine, but others give me some trouble. Right now... (1 Reply)
Discussion started by: jason_v
1 Replies
Login or Register to Ask a Question