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 02-24-2011, 02:44 AM   #1
maobin
Member
 
Registered: Feb 2011
Posts: 42

Rep: Reputation: 0
Problem with grep


Hi,
I wan to extract some information from ifconfig,

eg:
inet addr:123.123.123.123 Bcast:123.123.123.255 Mask:255.255.254.0

i wan to extract the mask value, how can i do that?
I've tried using
Code:
grep -o "Mask:*" test1.txt
but it only outputs "Mask:" I need to get 255.255.254.0

Any idea how should can I do it?
 
Old 02-24-2011, 02:57 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Code:
/sbin/ifconfig | grep -o "Mask:.*"
Hope this helps.
 
Old 02-24-2011, 03:00 AM   #3
JimmyKrak
LQ Newbie
 
Registered: Feb 2011
Posts: 13

Rep: Reputation: 0
Take a look at "cut"

example: ifconfig|grep "Mask"|cut -d":" -f4
 
Old 02-24-2011, 03:07 AM   #4
maobin
Member
 
Registered: Feb 2011
Posts: 42

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Hi,
Code:
/sbin/ifconfig | grep -o "Mask:.*"
Hope this helps.
oh.. i miss out the . haha.. thanks alot
 
  


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
[SOLVED] Problem using grep -f zoeplankton Linux - Newbie 5 11-26-2010 06:03 PM
Trying to understand pipes - Can't pipe output from tail -f to grep then grep again lostjohnny Linux - Newbie 15 03-12-2009 10:31 PM
grep problem spx2 Linux - Newbie 9 12-15-2005 01:22 AM
Grep problem chup Linux - General 7 04-17-2004 12:08 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

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

All times are GMT -5. The time now is 11:14 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
Open Source Consulting | Domain Registration