AWK /桑达:两个输入文件A和B其中只有第B换人根据阿? [英] AWK/Sed: two input files A and B where substitutions only on B according to A?
本文介绍了AWK /桑达:两个输入文件A和B其中只有第B换人根据阿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入有两个文件A和B
$猫
1单
2两
3 3
4 fyra
5 FEM
$ B类
一条1你好喂2三条喂五五
拟输出(AWK简单/桑达单行将被接受)
一一问好喂二三喂有限元FEM
解决方案
$的awk'NR == FNR {图[$ 1 = $ 2;接下来} {为(i = 1; ?I< = NF;我++)$ I =($ i的地图[$ i]:$ I)} 1'的fileA FILEB
一一问好喂二三喂有限元FEM
请注意,这将COM preSS的连续空白,以一个单一的空白字符的链。告诉我们,如果这是一个问题。
Input has two files A and B
$cat A
1 one
2 two
3 three
four fyra
five fem
$cat B
one 1 hello hallo 2 three hallo five five
Intended output (simplest AWK/Sed one-liner will be accepted)
one one hello hallo two three hallo fem fem
解决方案
$ awk 'NR==FNR{map[$1]=$2;next} { for (i=1;i<=NF;i++) $i=($i in map ? map[$i] : $i) } 1' fileA fileB
one one hello hallo two three hallo fem fem
Note that it will compress any chains of contiguous white space to a single blank char. Tell us if that is an issue.
这篇关于AWK /桑达:两个输入文件A和B其中只有第B换人根据阿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文