🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1630

Re: Stupid sed question

#1630
From: Paul John Falstad
Date: Sat, 27 Oct 1990 00:30
54 lines
2289 bytes
In article <118@mq.com> alan@mq.com (Alan H. Mintz) writes:
>(Hmmm. Hard to tell if this is the right group nowadays :)
>
>I'm trying to write a script to edit the /etc/ttytype file under XENIX. The
>idea is to search the file for the line for a given port and alter the
>terminal type associated with it. The ttytype file consists of lines
>like:
>
>wy60ak	ttya1
>svt1210	ttya2
>ansi	ttya3
>
>The separator between the fields is a tab character (\011, 0x09). So,

>tty='ttya1'
>ttytype='vt100n'
>
>line=`fgrep $tty /etc/ttytype`
>cat /etc/ttytype | sed "s/$line/$ttytype	$tty/" >tempfile
>#		This is a tab -----------^^^^^^

>This works great, if the file does not contain another terminal that starts
>with ttya1 (like ttya10):
>
>ansi	ttya1
>ansi	ttya10
>
>In this case, sed barfs with "command" garbled. What am I missing here ? I 

When there are two terminals that contain the string ttya1, $line is
being set to "ansi ttya1\nansi ttya10", since the output of fgrep has
two lines.  So sed sees this as its command:

s/ansi ttya1
ansi ttya10/vt100n ttya1/

which is garbled, since the first line has no ending delimiter.  Try
something like this instead:

line=`grep "[TAB]$tty$" /etc/ttytype`
cat /etc/ttytype | sed "s/$line/$ttytype $tty/" >tempfile

or better, replace both lines with:

sed "/[TAB]$tty\$/s/.*[TAB]/$ttytype[TAB]/" /etc/ttytype >tempfile

If you actually have more fields after the tty name, you may have to
change the \$ to another tab.

--
Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
"Your attention please.  Would the owner of the Baader-Meinhof shoulder-bag
which has just exploded outside the terminal please pick up the white
courtesy phone."
Technical Details
Message-ID: <3622@idunno.Princeton.EDU>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!milton!dali.cs.montana.edu!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!screen.Princeton.EDU!pfalstad
References: <118@mq.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!milton!dali.cs.montana.edu!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!screen.Princeton.EDU!pfalstad
From: pfalstad@screen.Princeton.EDU (Paul John Falstad)
Newsgroups: comp.unix.shell
Subject: Re: Stupid sed question
Keywords: sed XENIX
Message-ID: <3622@idunno.Princeton.EDU>
Date: 27 Oct 90 00:30:23 GMT
References: <118@mq.com>
Sender: news@idunno.Princeton.EDU
Organization: Princeton University, Princeton, New Jersey
Lines: 54