Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

egrep for any number of space and/or tabs

1,952 views
Skip to first unread message

iandid...@googlemail.com

unread,
Jun 29, 2012, 12:46:43 PM6/29/12
to
I need to egrep A records from a dns zone file... but there could be any number of spaces and/or tabs between the "IN" and the "A" on a line.

I've googled and tried various suggestions but am getting nowhere...

all tips and hints gratefully received

ian

hume.sp...@bofh.ca

unread,
Jun 29, 2012, 2:53:22 PM6/29/12
to
iandid...@googlemail.com wrote:
> I've googled and tried various suggestions but am getting nowhere...

egrep 'IN[ ]+A' dns.zone, where ' ' is a control-V<tab>
followed by a space? That doesn't work for you?

--
Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/

Cydrome Leader

unread,
Jun 30, 2012, 1:27:01 AM6/30/12
to
hume.sp...@bofh.ca wrote:
> iandid...@googlemail.com wrote:
>> I've googled and tried various suggestions but am getting nowhere...
>
> egrep 'IN[ ]+A' dns.zone, where ' ' is a control-V<tab>
> followed by a space? That doesn't work for you?

I'd do this

egrep "IN[[:space:]]A" dns.zone

not all egreps support it, but at least you're not dealing with invisible
characters inside commands. [:space:] is a magic value that matches spaces
and/or tabs or any combination. you'd have to lookup how it's defined
though.

iandid...@googlemail.com

unread,
Jul 2, 2012, 6:02:43 AM7/2/12
to
thanks guys... unfortunately neither suggestion works for me.

cheers anyway!

ian

hume.sp...@bofh.ca

unread,
Jul 2, 2012, 8:55:20 AM7/2/12
to
iandid...@googlemail.com wrote:
> thanks guys... unfortunately neither suggestion works for me.

Then I'm not sure anyone can help you without a real example from the
zone file, because there's something weird going on.

You might try using perl.

iandid...@googlemail.com

unread,
Jul 2, 2012, 9:50:48 AM7/2/12
to
On Monday, July 2, 2012 1:55:20 PM UTC+1, (unknown) wrote:

> Then I'm not sure anyone can help you without a real example from the
> zone file, because there's something weird going on.

having done some more tests I totally concur. If I create a seperate text file with

a line

fred<space>IN<spaces>A<spaces>1.2.3.4

the above works fine - just not with the current zone files..

cheers for your time

Ian

YTC#1

unread,
Jul 2, 2012, 2:21:08 PM7/2/12
to
On 07/ 2/12 01:55 PM, hume.sp...@bofh.ca wrote:
> iandid...@googlemail.com wrote:
>> thanks guys... unfortunately neither suggestion works for me.
>
> Then I'm not sure anyone can help you without a real example from the
> zone file, because there's something weird going on.
>
> You might try using perl.
>

Or nawk


--
Bruce Porter
"The internet is a huge and diverse community but mainly friendly"
http://blog.maui.co.uk/index.php/ytc/
There *is* an alternative! http://www.openoffice.org/

Winston

unread,
Jul 2, 2012, 3:07:02 PM7/2/12
to
iandid...@googlemail.com writes:
> thanks guys... unfortunately neither suggestion works for me.

Maybe "cat -v" would reveal separators other than space and tab?
Are you sure your command line quoted search string contained a real TAB
character?
-WBE

Andreas F. Borchert

unread,
Jul 3, 2012, 10:19:25 AM7/3/12
to
On 2012-06-29, iandid...@googlemail.com <iandid...@googlemail.com> wrote:
> I need to egrep A records from a dns zone file... but there could be
> any number of spaces and/or tabs between the "IN" and the "A" on a line.

This can be done using egrep (see the other follow-ups) or by Perl which
also shipped with Solaris and which provides a more convenient syntax for
regular expressions with tons of extra features (see "perldoc perlre"
for a summary). If you want to extract just the A-records (and no AAAA
records), I suggest to use following line

perl -ne 'print if /\bIN\s+A\b/' zone

Option "-n" is similar to "-n" of sed (implicit loop over all input
lines but without an implicit print) and "-e" tells that the following
argument is the actual Perl script. The statement causes all input lines
to be printed that match the given regular expression:

\b word boundary (you won't match WIN here)
\s space character including space, tabs etc. but no newline
\s+ at least one space character

Andreas.

mspr...@gmail.com

unread,
Jun 16, 2014, 7:06:47 PM6/16/14
to

Better late then never... do the following

<command> | /bin/sed 's/\t/ /g'

This will turn all the tabs into spaces, and then you can format
or do what-ever accordingly..

bwang...@gmail.com

unread,
Nov 30, 2016, 6:28:04 AM11/30/16
to
在 2012年6月30日星期六 UTC+8上午2:53:22,hume.sp...@bofh.ca写道:
> egrep 'IN[ ]+A' dns.zone, where ' ' is a control-V<tab>
> followed by a space? That doesn't work for you?
>
> --
> Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/

Thank you. It helps me.

Alekz

unread,
Dec 7, 2016, 7:20:38 PM12/7/16
to
My 2cents. Replace all occurrences of spaces and tabs with one space:

sed -e 's/[ ]*/ /g'

Press <space> and <tab> in the square brackets

Alekz

unread,
Dec 8, 2016, 7:41:21 AM12/8/16
to
Arrgh... a typo and I can't edit my message. It should be

sed -e 's/[ ][ ]*/ /g'

Ian

unread,
Dec 8, 2016, 11:42:03 AM12/8/16
to
Depending on your shell, in between the brackets, you might have to press:

space
Ctrl-V
tab

Some shells (e.g. bash) capture the tab and do filename completion,
Ctrl-V tells it not to, and that you really do want to put a tab into
the command line.

0 new messages