0

输入文件1:

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.

输出应该是这样的:

将输入 file1 的完整形式替换为输入 file2

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

4

1 回答 1

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)

这会发生吗?应该怎么做?

于 2013-02-18T13:05:21.763 回答