我的file.txt
:
Adam , 111
Adam ,222
Adam ,333
Tom ,111
Tom , 222
Tom, 333
Dick, 111
Dick, 222
Dick ,333
预期输出为:
My list
-----------------------
List for Adam
-----------------------
Adam 111
Adam 222
Adam 333
End of list for Adam
. My list
. -------------------
List for Tom
. ------------------
Tom 111
Tom 222
Tom 333
End of list for Tom
. My list
----------------------
List. For Dick
. ----------------------
Dick 111
Dick 222
Dick 333
End of list for Dick
我希望通过特定列中的人员姓名来溢出我的文件,并使用以下方法添加页眉页脚:
awk 'BEGIN {pttern } {action} END{pater}' myfile.txt
感谢您的回答并对版本表示歉意
答案1
Awk
方法:
awk 'BEGIN{ head = "List for"; tail = "End for list for" }
!a[$1]++ {
if (NR > 1) print tail, name ORS;
print head, $1;
name = $1
}
END{ print tail, name }1' file
输出:
List for Adam
Adam 111
Adam 222
Adam 333
End for list for Adam
List for Tom
Tom 111
Tom 222
Tom 333
End for list for Tom
List for Dick
Dick 111
Dick 222
Dick 333
End for list for Dick