Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


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

Rep: Reputation: 0
Question awk regex with variable


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 '/{print $6}'`

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

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

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

Please help!


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

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

Original Poster
Rep: Reputation: 0

Vielen Dank!

LG, bertl1982


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 08:10 PM.

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