Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My regex understanding seems to be in a jiffy.
I have a large file(say IPfile.txt) containing IP addresses (say in the range 10.0.0.0 to 10.255.255.255) among other things. I want to see the lines containing IP addresses 10.0.16.0 to 10.0.25.255. I am shooting the following command -
Code:
grep 10\.0\.[16-25]\.[0-255] IPFile.txt
However this does not seem to show me the desired output. I see IPs outside this range too.
here i have observed that when i give the range 10.0.[16-25].[0-255], the output shows me anything in the range
10.0.1.x
10.0.2.x.
10.0.1x.x
10.0.2x.x.
what could be a practical way to do this other than working around each line manually through a 27000 line file?!! Can grep be used in a manner to accept two digit ranges? if not grep what can be a better tool to use?
By contrast, [21-35] matches 1,2,3,or 5 (i.e. 2, the range 1-3, or 5)
Note that when you grep using a range, it only has to match one number in the range to print the line
To look for multi-digit patterns, you need expressions like these:
[0-9][4-8] (any digit followed by 4,5,6,7, or 8)
[0-9]\{3\} (3 occurences of any digit) (Use with egrep)
[2-4]5[0-9] (2,3,or 4; then 5, then any digit)
Note also:
"." means any character
"\." means the literal "."
what could be a practical way to do this other than working around each line manually through a 27000 line file?!! Can grep be used in a manner to accept two digit ranges? if not grep what can be a better tool to use?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.