Subject: shell script question (grep)
To: None <netbsd-help@netbsd.org>
From: Lubos Vrbka <shnek@chemi.muni.cz>
List: netbsd-help
Date: 02/09/2003 16:42:14
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}'
to get the B values for each line; then i'd use paste and awk or something
else to get the desired output. the problem is, that grep will print out
line for given A value only once => in case i have something like
(file1, values A)
. . . . . . 10
. . . . . . 11
. . . . . . 10
and
(file 2, values A B)
10 1
11 2
the result will be
1
2
(empty line)
does anyone know how to force grep to print the lines more than once? what
am i doing bad? some other approach to do this? i was thinking about reading
just one line from the file1 and piping this to grep, but it would be very
slow and ineffective... what more, i don't remember the command for printing
just one specified line... :o(
i'll be glad for any suggestions...
lubos
ps. just a remark... i don't use perl because i don't know the language...
:o)
-
#################################################
Lubos Vrbka
National Centre for Biomolecular Research
Masaryk university, Brno, Czech Republic
shnek@chemi.muni.cz
http://www.chemi.muni.cz/~shnek
tel. +420 541 129 508
#################################################