LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-17-2010, 08:14 AM   #1
bertl1982
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Rep: Reputation: 0
Question awk regex with variable


Hy!

I've a problem with bash scripting and can't solve it. I was searching for a solution but can't find anything which answers my question. ... maybe I'm to stupid to understand it at the moment ... so I hope there is anybody who can help me.

I will check the state of an port (in this case 125) with the followig line:

>PORT_STATE=`netstat -nat | awk '/0.0.0.0:125/{print $6}'`
>echo $PORT_STATE
LISTEN

Now I'm trying to set the port as an variable like this:

>PORT=125
>PORT_STATE=`netstat -nat | awk '/0.0.0.0:$PORT/{print $6}'`
>echo $PORT_STATE

But this dosn't work and I don't know how to do it correctly.

Please help!

Thanks!

bertl1982
 
Old 03-17-2010, 08:26 AM   #2
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 96
Code:
PORT=125
PORT_STATE=`netstat -nat | awk '/0.0.0.0:'$PORT'/{print $6}'`
echo $PORT_STATE
 
Old 03-17-2010, 08:38 AM   #3
bertl1982
LQ Newbie
 
Registered: Jan 2010
Posts: 5

Original Poster
Rep: Reputation: 0
@troop:

Vielen Dank!

LG, bertl1982
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What should some Regex match in awk? sebelk Programming 7 11-20-2009 06:38 PM
Awk regex question uncle-c Linux - Newbie 2 03-03-2009 08:30 AM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 12:08 AM
awk regex question Guest1234 Programming 6 12-25-2007 01:31 PM
Newbie SED / AWK / Regex command help request Critcho Linux - Newbie 10 03-19-2007 11:22 AM


All times are GMT -5. The time now is 11:40 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration