LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-13-2015, 12:06 AM   #1
Qwerti
LQ Newbie
 
Registered: Feb 2015
Posts: 3

Rep: Reputation: Disabled
getting variable integer values from grep


I want to write a Python script. In order to write it I need to figure out how to access the values associated with my signal level and bit rate.

If I use the following command

Code:
iwconfig | grep 'Signal level'
I get:

eth0 no wireless extensions.

lo no wireless extensions.

Link Quality=70/70 Signal level= -38 dBm


Obviously, I don't want Signal level. I want whatever it happens to be. In this case, it happens to be -38. Ditto Bit Rate...How do I grab -38 from the command line?
 
Old 02-13-2015, 12:41 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Here it is:

Code:
iwconfig | grep -E -o 'Signal level= .?[[:digit:]]+' | sed -e 's@Signal level= @@g'
 
Old 02-13-2015, 01:34 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
iwconfig 2>/dev/null | awk 'BEGIN{FS="[= ]+"} /Signal level=/ { print $7 }/Bit Rate=/ {print $4 } '

but if you want to write a python script, grab it inside python and do not use additional external tools.
 
Old 02-13-2015, 10:18 AM   #4
Qwerti
LQ Newbie
 
Registered: Feb 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
but if you want to write a python script, grab it inside python and do not use additional external tools.
Yeah, I was going to use os.system('command'). Do you have any suggestions on modules I should be looking at?
 
Old 02-15-2015, 04:35 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
no, you ought to try Popen and communicate, here is an example: http://www.moosechips.com/2010/07/py...dule-examples/ (but obviously you can find other ones too)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script to add integer values & get the sum demet8 Linux - Newbie 5 10-20-2012 02:46 PM
On what basis CHAIN integer values are generated in IPtables under iptables file? haariseshu Linux - Server 3 11-05-2009 05:25 AM
how to grep for only the values of a specific field hchoonbeng Linux - Newbie 3 11-19-2008 09:20 AM
reading integer values from excel using java - interprets it as float kshkid Programming 3 07-28-2008 01:53 AM
Matching values in a bash script grep, regex's ... ? maxvonseibold Linux - General 6 01-29-2007 07:07 AM


All times are GMT -5. The time now is 08:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration