For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > January 2005 > search for hex charcater in files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author search for hex charcater in files
Will Cardwell

2005-01-29, 3:57 pm

I'm looking for unwanted occurrences of hex A0 in each text file of a
certain file spec. I'm using SunOS Unix.

To test, I have tried:

egrep /\x41/ foobar and similar to try to reproduce:
grep A foobar

as well as similar with awk. I tried different quoting etc. but can't get it
to work.

Can anyone help?

Thanks so much,
Will Cardwell


Paul Pluzhnikov

2005-01-29, 3:57 pm

"Will Cardwell" <williamcardwell@yahoo.com> writes:

> I'm looking for unwanted occurrences of hex A0 in each text file of a
> certain file spec. I'm using SunOS Unix.


od -x foobar | grep 'a0'

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Stephane CHAZELAS

2005-01-29, 3:57 pm

2005-01-29, 15:19(+00), Will Cardwell:
> I'm looking for unwanted occurrences of hex A0 in each text file of a
> certain file spec. I'm using SunOS Unix.
>
> To test, I have tried:
>
> egrep /\x41/ foobar and similar to try to reproduce:
> grep A foobar
>
> as well as similar with awk. I tried different quoting etc. but can't get it
> to work.
>
> Can anyone help?

[...]

/usr/dt/bin/dtksh -c '
find . -type f -exec /usr/xpg4/bin/grep -q $'\xa0' \; -print'

Should output a list of text files containing the character
0xa0.

--
Stéphane
Stephane CHAZELAS

2005-01-29, 3:57 pm

2005-01-29, 16:27(+00), Stephane CHAZELAS:
[...]
> /usr/dt/bin/dtksh -c '
> find . -type f -exec /usr/xpg4/bin/grep -q $'\xa0' \; -print'


Sorry, I forgot to escape the inner quotes.

/usr/dt/bin/dtksh -c "
find . -type f -exec /usr/xpg4/bin/grep -q \$'\xa0' \; -print"


--
Stéphane
Will Cardwell

2005-01-30, 8:56 am


"Stephane CHAZELAS" <this.address@is.invalid> wrote in message
news:slrncvnem8.5o4.stephane.chazelas@spam.is.invalid...
> 2005-01-29, 16:27(+00), Stephane CHAZELAS:
> [...]
>
> Sorry, I forgot to escape the inner quotes.
>
> /usr/dt/bin/dtksh -c "
> find . -type f -exec /usr/xpg4/bin/grep -q \$'\xa0' \; -print"
>
>
> --
> Stéphane


/usr/dt/bin/dtksh -c "find . -type f -exec /usr/xpg4/bin/grep -q \$'\xa0' {}
\; -print"

worked fine. ( Note {})

Thanks so much! I learned a lot finding the {} bug.

Best,
Will


Will Cardwell

2005-01-30, 8:56 am


"Paul Pluzhnikov" <ppluzhnikov-nsp@charter.net> wrote in message
news:m31xc4gsc4.fsf@salmon.parasoft.com...
> "Will Cardwell" <williamcardwell@yahoo.com> writes:
>
>
> od -x foobar | grep 'a0'
>
> Cheers,
> --


Thanks! This worked fine but of course doesn't give file name and shows only
the hex. Nice amd simple.

Regards,
Will.


moi

2005-01-30, 3:57 pm

Will Cardwell wrote:
> "Stephane CHAZELAS" <this.address@is.invalid> wrote in message
> news:slrncvnem8.5o4.stephane.chazelas@spam.is.invalid...


>
>
> /usr/dt/bin/dtksh -c "find . -type f -exec /usr/xpg4/bin/grep -q \$'\xa0' {}
> \; -print"
>
> worked fine. ( Note {})
>
> Thanks so much! I learned a lot finding the {} bug.
>


man find

HTH
AvK
Paul Pluzhnikov

2005-01-30, 3:57 pm

"Will Cardwell" <williamcardwell@yahoo.com> writes:

>
> Thanks! This worked fine but of course doesn't give file name and shows only
> the hex. Nice amd simple.


That was left as an exercise for the reader :-)

You already know the 'find' soultion, but here is the answer using 'od':

for i in foobar.*; do
od -x $i | grep 'a0' > /dev/null && echo $i
done

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Will Cardwell

2005-01-30, 3:57 pm


"Paul Pluzhnikov" <ppluzhnikov-nsp@charter.net> wrote in message
news:m3k6pugbj7.fsf@salmon.parasoft.com...
> "Will Cardwell" <williamcardwell@yahoo.com> writes:
>
>
> That was left as an exercise for the reader :-)
>
> You already know the 'find' soultion, but here is the answer using 'od':
>
> for i in foobar.*; do
> od -x $i | grep 'a0' > /dev/null && echo $i
> done
>


That will do it and I love it! I had not seen "od" before and looked it up
in man. Thanks again!
Will


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com