Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Linux Programming & Scripting > Grepping for octal numbers

Forgot Password?
 Linux Programming & Scripting   C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 06-16-2009   #1 (permalink)
Just Joined!
 
Join Date: Oct 2006
Posts: 1
Grepping for octal numbers

Gentlemen,

I have been trying for 2 days to solve this problem, so I am ready to ask for help.
Background: I am trying to move my CD collection into iTunes, and ultimately to my
iPod. When the titles are looked up in the Gracenotes database, some titles,
particularly classical titles, come back with embedded non-printing characters. I am
seeing octal 357, 200, and 242 using OD. I would like to strip these out, as they
interfere with some copy tools I use.

I don't think this problem can be solved in Windows, and OSx refuses to touch my
NTFS file system except for reading. So I am using Suse 11 which has no such qualms.

I can iterate over the file system, I can write the rename portion & submit it to a
shell. I need to be able to grep for an octal pattern. I understand grep accepts a
regex, but I can't seem to get the syntax right. It would be something like
" ... | grep '\357' | ..... etc. This doesn't work, BTW.

If you have ever done this, or just know how to do it, I would appreciate a heads up. As a side exercise, I would like to print the character corresponding to an
octal pattern on the screen. Something like "printf "%c" \357 ", but one that works.

Any help is much appreciated. Feel free to email me direct.

Thanks,
Greg
Greg Peterson is offline  



Reply With Quote
Old 06-17-2009   #2 (permalink)
Linux Guru
 
Rubberman's Avatar
 
Join Date: Apr 2009
Location: I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
Posts: 3,437
For octal values, you need to preceed the actual data value with a zero (0), so for octal 354 you would use \0354. Try that - no guarantees, but it works in C/C++. Also, if this is on the command line, the backslash is an escape character, so you may need to double it up, as in "\\0354".
__________________
Sometimes, real fast is almost as good as real time.
Rubberman is offline   Reply With Quote
Old 06-17-2009   #3 (permalink)
Trusted Penguin
 
Cabhan's Avatar
 
Join Date: Jan 2005
Location: Boston, MA, USA
Posts: 2,740
An alternative, for the record, might be to simply grep for anything that is not a valid character. So you might try:
Code:
egrep '[^[:alnum:][:punct:][:space:]]'
egrep is the same as grep -E, which enables POSIX Extended Regular Expressions. I then create a character class that matches anything that is not alphanumeric, a punctuation, or a space.

This way, you don't need to worry about matching something specific, but instead can worry about only preserving certain characters.

As for your other question, to print in Bash a character knowing only its octal value, you use this special notation:
Code:
echo $'\nnn'
So for instance:
Code:
alex@danu ~ $ echo $'\101'
A
I hope that helps!
__________________
DISTRO=Ubuntu
Registered Linux User #388732
Cabhan is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 02:43 PM.






© 2000 - - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.1