我需要帮助,我有:
/usr/include/slang.h:include
/usr/include/slang.h:star
/usr/include/slang.h:load
/usr/include/byteswap.h:include
我必须合并才能在shell中得到结果:
/usr/include/slang.h include star load
/usr/include/byteswap.h include
我该怎么办?
答案 0 :(得分:0)
$ cat merge.txt
/usr/include/slang.h:include
/usr/include/slang.h:star
/usr/include/slang.h:load
/usr/include/byteswap.h:include
$ cat merge.sh
#!/bin/bash
for path in $(awk -F':' '{print $1}' merge.txt | uniq)
do
values=$(grep "${path}" merge.txt | awk -F':' '{print $NF}' | tr '\n' ' ')
echo "${path}" "${values}"
done
输出:
$ ./merge.sh
/usr/include/slang.h include star load
/usr/include/byteswap.h include