(使用Linux)我有许多文本文件,其中包含标题,后跟几行信息。我需要将标题移动到"段落#34;。
的每一行Paragraph1Header
P1L1Col1 P1L1Col2
P1L2Col1 P1L2Col2
Paragraph2Header
P2L1Col1 P2L1Col2
P2L2Col1 P2L2Col2
到
P1L1Col1 Paragraph1Header P1L1Col2
P1L2Col1 Paragraph1Header P1L2Col2
P2L1Col1 Paragraph2Header P2L1Col2
P2L2Col1 Paragraph2Header P2L2Col2
答案 0 :(得分:1)
将程序放入文件 pr.awk 并运行awk -f pr.awk input.txt
NF == 1 {
h = $1
next
}
NF > 1 {
match($0, "[[:space:]]+")
i = RSTART + RLENGTH - 1
fst = substr($0, 1, i)
rst = substr($0, i+1)
print fst h " " rst
}