0

I'm trying to make a script what automatically replace a word in the text file.

In a.v,
BIRA_0     0
BIRA_1     400
BIRA_2     800
BIRA_3     C00
...

in b.v,
BIRA_0[25:0]
BIRA_0[95:26]
BIRA_0[125:96]
BIRA_0[255:125]
BIRA_1[5:0]
BIRA_1[25:6]
...


Result,

0[25:0]
0[95:26]
0[125:96]
0[255:125]
400[5:0]
400[25:6]
...

Of course, I can use

$sed "s/BIRA_0/0/" b.v > result

but the problem is that the file a.v contains many such replacement cases, so I'd like to make it automatically by Cshell script.

AdminBee
  • 22,803
Carter
  • 136

1 Answers1

1

So long as a.v does not contain any regular expression special characters, then regardless of the shell that you are using you could do something like

awk '{printf "s/^%s/%s/\n", $1, $2}' a.v | sed -f - b.v

Alternatively, with awk alone:

awk 'NR==FNR {a[$1]=$2; next} {print a[$1] "[" $2}' a.v FS="[" b.v
steeldriver
  • 81,074