Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Find ASCII character in a file

Posted on 2003-03-12
15
Medium Priority
?
3,287 Views
Last Modified: 2008-01-16
I'm using a Korn Shell. I need to find all files in a directory having character with ascii code 128. Can you please help?
Thanks
0
Comment
Question by:prashant_n_mhatre
  • 6
  • 5
  • 2
  • +2
15 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8122154
grep -l "search_pattern" *

-l will return only filename

about char(128)  let me tested first
0
 
LVL 4

Author Comment

by:prashant_n_mhatre
ID: 8122231
Thanks HamdyHassan !!!
I know "grep". I don't know how to use ascii-128 character code for search.
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8122353

idea, to dump the file and search the dump

prompt> od -c filename | grep 307




0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8122383
Why 307 ?


1557 bin/ee> cat filename.txt
hello
char 128 is  Ç


1556 bin/ee> od -c filename.txt
0000000   h   e   l   l   o  \n   c   h   a   r       1   2   8       i
0000020   s         307  \n
0000025

-----------------
what -c means ?
-----------------
    -c        Display  single-byte  characters.   Certain   non-
               graphic  characters  appear as C-language escapes:
               null=\0, backspace=\b, form-feed=\f,  new-line=\n,
               return=\r,  tab=\t; others appear as 3-digit octal
               numbers.  For example:
               echo "hello world" | od -c
               0000000   h   e   l   l   o       w    o    r    l
               d  \n
               0000014

0
 
LVL 4

Author Comment

by:prashant_n_mhatre
ID: 8122385
i'm doing the same. I'm wondering...Is there any command that can directly take care of this..
0
 
LVL 4

Author Comment

by:prashant_n_mhatre
ID: 8122450
Sorry..your another comment was not there when I posted this. I'm not looking for a pattern "char-128". I'm having a character in a file whose ascii value is 128.
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8122587
Yes, I know you are looking for char with ascii value 128

which is listed at the ascii table
http://www.dotnet4all.com/default.asp?NavID=486

128  Ç

for some reason, when I post, EE convert "Ç" to  "G"

Any way, try
prompt> od -c filename | grep 307

and let me know if that working or not
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8122608

\307 is C-language escapes for ASCII 128

and when you use "od -c " it appears as 307.


0
 
LVL 4

Author Comment

by:prashant_n_mhatre
ID: 8122797
will it be 307 or 200?
0
 
LVL 1

Accepted Solution

by:
rob-g earned 200 total points
ID: 8126361
prashant_n_mhatre,

Use echo to create an environment variable that holds the ascii 128 character. echo deals in Octal so this is actually 0200.
You can then use this as the pattern parameter to grep, e.g.

search_char=`echo "\0200"`
grep -l ${search_char} *
0
 
LVL 2

Expert Comment

by:jimbb
ID: 8126415
Hmm.  Is there an ascii 128 character?  man ascii, I don't see it in there.
0
 
LVL 1

Expert Comment

by:rob-g
ID: 8126477
Ascii codes go beyond that shown in man ascii.
The characters beyond this range cover the multinational character set (e.g. the French c-cedilla ascii 231).

Try the following to display a Scandinavian (?) 'o' character (ascii 248).

echo "\0370"
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8127265
It's \0307  not \0200

and yes it's working using grep echo idea

1592 bin/ee> grep `echo "\0307"` filename.txt
char 128 is  Ç


so you can use the following command

grep -l `echo "\0307"` *

where
` is back quote



             
0
 
LVL 1

Expert Comment

by:Santunes
ID: 8128042
Hi,
the script below achieves your need.

for f in `ls`
do
 awk '/\200/ {print FILENAME}' $f
done


good luck!
0
 
LVL 4

Author Comment

by:prashant_n_mhatre
ID: 8128176
Thank you all for your help and suggestions.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question