将较短的表格转换为完整的表格

时间:2013-02-18 12:42:13

标签: shell

输入file1:

IT  : Information Technology
B.Tech : Graduation
CS : computer science

输入文件2:

B.Tech has the different groups.
One of several groups is IT and it has CS.
Most of the students are selecting these two groups.

oputput应该像:

将输入file1的fullforms替换为输入file2

任何人都可以帮助创建使用awk / sed的shell脚本...

1 个答案:

答案 0 :(得分:1)

 awk -F' : ' 'NR==FNR{a[$1]=$2;next}{for(x in a)gsub(x,a[x])}1' file1 file2

输出将是:

kent$  awk -F' : ' 'NR==FNR{a[$1]=$2;next}{for(x in a)gsub(x,a[x])}1' file1 file2
Graduation has the different groups.one of several groups is Information Technologyand it has computer science.Most of the students selecting these two groups.

然而您需要注意一个问题:

递归替换问题

例如:

CS : computer science (CS)

会发生这种情况吗?应该怎么做?