![](_gb_images/_gb_sitenav_spacer.gif) |
![](_gb_images/_gb_clear.gif) |
`grep' etc. with non-ascii text files
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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 ![Smilie](https://forums.macnn.com/images/smilies/oldschool/smile.gif)
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 ![Smilie](https://forums.macnn.com/images/smilies/oldschool/smile.gif)
(
Last edited by VEGAN; May 30, 2003 at 06:18 AM.
)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status:
Offline
|
|
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.
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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 ![Smilie](https://forums.macnn.com/images/smilies/oldschool/smile.gif) 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!
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status:
Offline
|
|
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
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Moderator Emeritus ![](stars/star_5_purpleoil.png)
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
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
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
Originally posted by Xeo:
alias foo "grep \!* filename"
would make:
foo string
the same as:
grep string filename
Thanks ![Smilie](https://forums.macnn.com/images/smilies/oldschool/smile.gif)
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_clear.gif) |
|
|
|
![](_gb_images/_img_misc/_gb_mb_previousthread-off.gif)
|
|
![](_gb_images/_gb_clear.gif) |
Forum Rules
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
![](_gb_images/_gb_clear.gif) |
|
![](_gb_images/_gb_sitenav_spacer.gif) |