像大多数UNIX(样式)工具一样,tac既不会覆盖orignal文件也不会写一个新文件,它会打印到stdout,用tac写一个新文件你会使用重定向tac文件> newfile这会将反转的文件保存到newfile中.单独使用tac无法满足您的需求,您需要一个脚本.
这是awk中的一个:
{
# store each line in the array line
line[n++] = $0
}
/{/ {
# get the line number of the last line containing {
first=NR
}
!/}/ {
# get the line number of the last line not containing }
last=NR
}
END {
# print first section in order
for (i=0;i
print line[i]
# print second section in reverse order
for (i=last-1;i>=first;i--)
print line[i]
# print last section in order
for (i=last;i
print line[i]
}
保存到文件说反向然后运行awk -f reverse file:
$awk -f reverse file
page 0 0 0 none
{
layer 0 0 0 "1line" 0 8 8 3
{
sector 0 -1 0 32
{
device 1 0 1 "ground" 32 56 1 1 0
...
...
...
analog 1 0 1 0 1 321234 11.5 43 1 1 0
status 1 0 1 0 1 431232 "transformer" 23 12
point_name 0 0 34543 34 44 1 1 0
}
}
}
使用重定向创建新文件awk -f reverse file>新文件.