Mailing List ArchiveSupport open source code!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: tlug: sed ?
- To: tlug@example.com
- Subject: Re: tlug: sed ?
- From: "Stephen J. Turnbull" <turnbull@example.com>
- Date: Wed, 23 Apr 1997 16:07:34 +0900
- In-reply-to: Your message of "Wed, 23 Apr 1997 10:22:42 +0900." <XFMail.970423103348.schweiz@example.com>
- Reply-To: tlug@example.com
- Sender: owner-tlug
-------------------------------------------------------- tlug note from "Stephen J. Turnbull" <turnbull@example.com> -------------------------------------------------------- >>>>> "Jim" == Jim Schweizer <schweiz@example.com> writes: Jim> After the great help a couple of weeks ago on using sed to Jim> strip headers from email I decided to try to learn a little Jim> more about it. So, I ordered the O'Reilly 'sed & awk' book Jim> and got to work. Jim> The problem is, sometime things don't work as advertised. For Jim> example in chapter 3 you're supposed to make a program for Jim> making single replacements called 'gres' which looks like: Jim> jim:~/bin$ cat gres Hmmmm... where's your magic shell interpreter thingie? Try inserting #!/bin/sh because bash and sh are not the same, quite, but calling bash as sh makes it much more compatible. This in fact doesn't work here :-) Jim> if [ $# -lt "3" ] Jim> then Jim> echo Usage: gres pattern replacement file Jim> exit 1 Jim> fi Jim> pattern=$1 Jim> replacement=$2 Jim> if [ -f $3 ] Jim> then Jim> file=$3 Jim> else Jim> echo $3 is not a file Jim> exit 1 Jim> fi Jim> A="'echo | tr '\012' '\001' '" Jim> Jim> sed -e "s$A$pattern$A$replacement$A" $file I assume that this is a hack which allows you to use a nonprintable, and thus highly unlikely to appear in the pattern or replacement, separator in the `s' command. Such hacks tend to be very unportable across shells. If you substitute backquotes for the "' and '" pairs, it works. I couldn't find a way to get around the shell variable A, though. Jim> When I try to use it though I get the error: Jim> sed: Unknown option to 's' Me, too. Jim> So I tried in on both my Slackware setup and SparkLinux with Jim> the same result. Jim> The book was written and tested on a SparcStation 1 running Jim> SunOS 4.0. Is the Linux sed version different? I'm using GNU Jim> sed version 2.05; should I upgrade? It's not sed that's different, it's the shell. Our Suns run csh by preference, maybe this is a csh-ism. FIRST, blame the shell. Then look for problems with other programs ;-) Steve -- Stephen J. Turnbull Institute of Policy and Planning Sciences Yaseppochi-Gumi University of Tsukuba http://turnbull.sk.tsukuba.ac.jp/ Tel: +81 (298) 53-5091; Fax: 55-3849 turnbull@example.com ----------------------------------------------------------------- a word from the sponsor will appear below ----------------------------------------------------------------- The TLUG mailing list is proudly sponsored by TWICS - Japan's First Public-Access Internet System. Now offering 20,000 yen/year flat rate Internet access with no time charges. Full line of corporate Internet and intranet products are available. info@example.com Tel: 03-3351-5977 Fax: 03-3353-6096
- Follow-Ups:
- Re: tlug: sed ?
- From: Jim Schweizer <schweiz@example.com>
- References:
- tlug: sed ?
- From: Jim Schweizer <schweiz@example.com>
Home | Main Index | Thread Index
- Prev by Date: Re: tlug: Broken fs?
- Next by Date: RE: tlug: sed ?
- Prev by thread: tlug: sed ?
- Next by thread: Re: tlug: sed ?
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links