Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > `grep' etc. with non-ascii text files

`grep' etc. with non-ascii text files
Thread Tools
VEGAN
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
May 30, 2003, 06:12 AM
 
I'd like to search a file at command line, but I'm not sure how this would work.

I have an GUI app "WorkLookup" that uses "edict" for Japanese-English dictionary. It's fantastic... but not perfect. In other words, I need a better searching method.

The dictionary can be opened in TextEdit [encoding "Japanese EUC"], but that is not exactly what I want. I'd like to do a something like

cat edict | grep "KANJI"

I could search the whole file for a specific kanji sign in TextEdit hitting COMMAND-G but that's not the best solution.

I know that Terminal.app HAS Japanese support [to some extent] `ls -v' shows file/directory names in Japanese.
However, how could I `grep' in Japanese? I've never tried this.

Any thoughts?


EDITED:

Never mind
I figured it out

It looked at first that it wouldn't work, but then if I tried it anyway, it was just fine!
I set the Terminal encoding to Japanese EUC; if I now tried to type the grep search pattern it showed up as "??" and that made me worried and I thought something was wrong. But actually, it works
( Last edited by VEGAN; May 30, 2003 at 06:18 AM. )
     
Camelot
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
May 31, 2003, 08:03 AM
 
FWIW, you never have to cat a file and pipe it into grep. grep will accept a filename as a parameter.

cat filename |grep somestring

is the same as:

grep somestring filename

without the overhead of cat and pipes.
As you'd expect, filename can be wildcarded to search a number of files in one hit.
Gods don't kill people - people with Gods kill people.
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Jun 2, 2003, 05:02 AM
 
Originally posted by Camelot:
FWIW, you never have to cat a file and pipe it into grep. grep will accept a filename as a parameter.

cat filename |grep somestring

is the same as:

grep somestring filename

without the overhead of cat and pipes.
As you'd expect, filename can be wildcarded to search a number of files in one hit.

But as I made it into an "alias" and I didn't know how to make an alias so that it would get the "somestring"... it was easier for me to `cat' it first. And there is not a BIG overhead from it I guess... it's not like I'm using 100% of my computer's CPU all the time...

But if you know how to make and alias that will do what I'm looking for, let me know, please!
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Jun 2, 2003, 01:54 PM
 
I'm not sure about an alias, but it could be done with a shell function. In BASH, it would look like this:

  function foo { grep "$*" filename; }

You would use it just like you would an alias:

  foo somestring

Would be equivalent to:

  grep "somestring" filename
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
Jun 4, 2003, 06:26 PM
 
Originally posted by VEGAN:
But as I made it into an "alias" and I didn't know how to make an alias so that it would get the "somestring"... it was easier for me to `cat' it first. And there is not a BIG overhead from it I guess... it's not like I'm using 100% of my computer's CPU all the time...

But if you know how to make and alias that will do what I'm looking for, let me know, please!
alias foo "grep \!* filename"

would make:

foo string

the same as:

grep string filename
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Jun 6, 2003, 01:29 PM
 
Originally posted by Xeo:
alias foo "grep \!* filename"

would make:

foo string

the same as:

grep string filename
Thanks
     
   
 
Forum Links
Forum 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
Top
Privacy Policy
All times are GMT -4. The time now is 06:55 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,