LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 03-23-2017, 03:57 AM   #1
jamiebbbb
Member
 
Registered: Mar 2017
Location: Victoria, Australia
Distribution: Debian Wheezy
Posts: 34

Rep: Reputation: Disabled
Post using grep to find the network interface name.


Hi

I hope someone can help me.I have a script that runs this command
iwconfig 2>&1 | grep 802.11 | grep' + interface'
The interface is a variable

This part of the script works

iwconfig 2>&1 | grep 802.11

the output is
wlan0 IEEE 802.11 ESSID:"Virus"

this command grep' + interface
it is meant to when it receives it variable input - output the individual interfaces.
wlan0
eth0
It doesn't
I have experimented with various grep commands
the only way i have been able to do the task successfully
is to grep iwconfig to a file called net.txt
then
awk '/wlan0/ {print $1}' net.txt
is there a way that i can do it just using the Grep command ??

Thanks
jamie

Last edited by jamiebbbb; 03-23-2017 at 03:59 AM.
 
Old 03-23-2017, 04:24 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
Welcome.

You'll need to look at the different styles of quoting. The single quotes ' ' mean to use everything between them as a a literal. The double quotes " " mean to interpret what's between them through the shell first. The latter is what you want since it will allow you to put a variable in there first. With awk you can assign environment variables to awk variables using -v

Code:
interface="wlan0"

iwconfig 2>&1 | grep "$interface"

iwconfig 2>&1 | awk -v i=$interface '$0 ~ i { print $1 }'
Compare:

Code:
interface="wlan0"
echo '$interface'
echo "$interface"

Last edited by Turbocapitalist; 03-23-2017 at 04:25 AM.
 
Old 03-23-2017, 05:52 AM   #3
jamiebbbb
Member
 
Registered: Mar 2017
Location: Victoria, Australia
Distribution: Debian Wheezy
Posts: 34

Original Poster
Rep: Reputation: Disabled
extremely grateful - thank you for sharing your knowledge - much appreciated

Last edited by jamiebbbb; 03-23-2017 at 05:54 AM.
 
  


Reply



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
Find MAC address of the 'main' network interface arizonagroovejet Linux - General 4 05-14-2014 01:08 PM
[SOLVED] how to use cp find and grep together to copy a list of files using find with grep babhijit Linux - Newbie 10 07-03-2013 12:25 PM
Find the config file of a network interface helptonewbie Programming 4 11-08-2007 04:51 AM
unable to find network interface (ipw3945) walter81 Linux - Wireless Networking 3 09-28-2007 05:41 PM
Urgent : How to find whether the Network Interface is DHCP enabled or not ? abha_shrimal Linux - Networking 3 12-15-2005 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:36 PM.

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
Open Source Consulting | Domain Registration