Subject: Re: shell script question (grep)
To: None <netbsd-help@netbsd.org>
From: Peter Seebach <seebs@plethora.net>
List: netbsd-help
Date: 02/09/2003 11:06:04
In message <004101c2d051$d26bbe40$d200a8c0@mshome.net>, "Lubos Vrbka" writes:
>hi,
>sorry for a stupid (and slightly off-topic) question, but i cannot find a
>solution myself :o( i'm writing a shellscript for following purpose:

>i've 2 files: first file contains 7 columns, in the last one there's a
>number A. A isn't unique, it may occur on any number of lines. in the second
>file i've a "translation table", i.e.  for every number A, there's given
>some other number B. there the A values are unique. now i want to replace
>all A values in the first file with the appropriate B values from the second
>file. i wanted to use following expression:

>awk '{print "^"$7"\ "}' file1 | grep -f - file2 | awk '{print $2}'

Hmm.  I don't think this is the right way to do it.

How many lines are there in file 2?

If not many, just build a sed command line for them.

Or:
	while read i j < file2
	do	sed -e "s/$i\$/$j/" < file1 > file1.out
		mv file1.out file1
	done

It's inefficient, but who cares?  This does the whole thing, and if it takes
a while to run, go watch a movie or something.

-s