如何从文件中下面给定的模式中删除重复的单词
文件模式:
/bin/sh --promote-module test-c_abc_toy_debug_v2_3_1-1.0.140603101548 --repo-id Test-rhel-appdev-sun-puppet
/bin/sh --promote-module test-c_def_debug_v2_3_1-1.0.140603101548 --repo-id Test-rhel-appdev-sol-puppet
/bin/sh --promote-rpm c-test-hell-debug-231-2.3.1-140603101548.noarch.rpm,c-test-hell-debug-231-2.3.1-140603101548.noarch.rpm --repo-id Test-rhel-6-server-x86_64-appdev-sun
/bin/sh --promote-rpm c-test-heaven-debug-2.3.1-140603101548.noarch.rpm,c-test-heaven-debug-2.3.1-140603101548.noarch.rpm,c-test-heaven-prod-2.3.1-140603101548.noarch.rpm --repo-id Test-rhel-6-server-x86_64-appdev-sol
期望的输出:
/bin/sh --promote-module test-c_abc_toy_debug_v2_3_1-1.0.140603101548 --repo-id Test-rhel-appdev-sun-puppet
/bin/sh --promote-module test-c_def_debug_v2_3_1-1.0.140603101548 --repo-id Test-rhel-appdev-sol-puppet
/bin/sh --promote-rpm c-test-hell-debug-231-2.3.1-140603101548.noarch.rpm --repo-id Test-rhel-6-server-x86_64-appdev-sun
/bin/sh --promote-rpm c-test-heaven-debug-2.3.1-140603101548.noarch.rpm,c-test-heaven-prod-2.3.1-140603101548.noarch.rpm --repo-id Test-rhel-6-server-x86_64-appdev-sol
请注意:
答案 0 :(得分:0)
我认为您的数据在第三列只有重复的字词(当FS =''时)。如果没有,这将是错误的。 下面的脚本适用于GNU awk。
cat your_data_file | awk '
{
system("echo " $3 "| tr , \"\\n\" | sort | uniq | paste -sd, > tmp ")
"cat tmp" | getline $3
close("cat tmp")
system("rm tmp")
print $0
}
'