www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/12/15:16:16

Message-ID: <915C65C50371D11187AD0000F881B9A401858D2A@bcarua62.ca.nortel.com>
From: "Ian Chapman" <Ian DOT Chapman DOT ichapman AT nt DOT com>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>
Subject: Bash and sed
Date: Thu, 12 Nov 1998 14:18:36 -0500
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.0.1460.8)
Reply-To: djgpp AT delorie DOT com

Hi all,
	I'm learning awk and sed got the book.  It has the following program
as a work round for gres not being in a Unix distribution.  I'm running bash
1.14.7 and sed 3.02
I.e. the normal djgpp stuff for PC.

	The line ... A="`echo | tr '\012' '\001'`" ... is to ensure
portability.  However what we have gives 
"unknown option to s".  I changed the line:- from 
sed -e "s$A$pattern$A$replacement$A" $file 

To
sed -e "s/$pattern/$replacement/" $file

	This change has helped no end.  Once again your comments will be of
enormous help.  Also should I be in a login or interactive mode?

	Regards Ian.


#! /bin/sh

if [ $# -lt "3" ] 
then 
	echo Usage: gres pattern replacement file
	exit 1
fi
pattern=$1
replacement=$2
if [ -f $3 ] 
then 
	file=$3
else
	echo $3 is not a file.
	exit 1
fi
A="`echo | tr '\012' '\001'`"
sed -e "s$A$pattern$A$replacement$A" $file


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019