NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Logical OR With Grep
Topic: GNU/Linux   Posted:2006-05-07
Printer Friendly: Print

spacerspacer
Say you have a file that has seventeen entries that look like this:

[usr-1@srv-1 ~]$ cat nmapout.txt
Starting nmap 3.70 ( http://www.insecure.org/nmap/ ) at 2006-05-05 13:41 PDT
Interesting ports on 10.50.100.1:
(The 1656 ports scanned but not shown below are in state: closed)
PORT      STATE SERVICE
22/tcp    open  ssh
111/tcp   open  rpcbind
6000/tcp  open  X11
32771/tcp open  sometimes-rpc5
Device type: general purpose
Running: Linux 2.4.X|2.5.X|2.6.X
OS details: Linux 2.5.25 - 2.6.3 or Gentoo 1.2 Linux 2.4.19 rc1-rc7)
Uptime 2.789 days (since Tue May  2 18:48:20 2006)
.
.
.
Interesting ports on 10.50.100.79:
(The 1657 ports scanned but not shown below are in state: closed)
PORT     STATE SERVICE
22/tcp   open  ssh
111/tcp  open  rpcbind
1024/tcp open  kdm
MAC Address: 00:60:97:97:CC:04 (3com)
Device type: general purpose
Running: Linux 2.4.X|2.5.X
OS details: Linux 2.4.0 - 2.5.20
Uptime 0.159 days (since Fri May  5 10:12:22 2006)
Nmap run completed -- 80 IP addresses (17 hosts up) scanned in 1178.103 seconds

See this article for a background on what is happening here. A quick way to generate a list of IP addresses and kernel versions is to do a grep that uses a logical OR. What we need to do is look for "Interesting" OR "Running". Grep seems like the obvious choice, however the catch is you need to use extended regular expressions. There are two ways to do this:

[usr-1@srv-1 ~]$ grep -E "Running|Interesting" nmapout.txt
[usr-1@srv-1 ~]$ egrep "Running|Interesting" nmapout.txt

Both reflect the file:

Interesting ports on 10.50.100.1:
Running: Linux 2.4.X|2.5.X|2.6.X
.
.
.
Interesting ports on 10.50.100.79:
Running: Linux 2.4.X|2.5.X
[usr-1@srv-1 ~]$





Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS