?
Solved

Find ASCII character in a file

Posted on 2003-03-12
15
Medium Priority
?
3,245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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
Course of the Month12 days, 13 hours left to enroll

777 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