如何先移动文件的最后一行? [英] How I can move last line of a file first?
问题描述
我有一个文件,按顺序包含 3 行:
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_off.vtran"bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_on.vtran"bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_sanity_dft.vtran"
我必须按照这个顺序一一执行unix命令行中的所有行:
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_sanity_dft.vtran"bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_off.vtran"bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_on.vtran"
我如何重新排列 &使用单个命令行执行所有 3 个命令?
我已经按照你的建议尝试了:
line1: echo startline2: bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_sanity_dft.vtran"第 3 行:回声你好line4: bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_off.vtran"第5行:回声再见line6: bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_on.vtran"第 7 行:回声结束
它仍然只执行 line1 &线2.之后退出那里..
你可以使用tac
(连接并反向打印文件),在最后打印第一项然后反向返回:
tac 文件 |awk 'NR==1 {行=$0;下一个} 1;END{打印行}' |战术
更新
<块引用>非常感谢 fedorqui 对我第一部分问题的回答.一世可以将命令的输出重定向到文件 &从命令行一一执行.相反,你能向前迈出一步吗?建议一种在单个命令中执行此操作的方法(无需重定向到档案及来源)
您可以通过管道传输到 bash:
tac 文件 |awk 'NR==1 {行 =$0;下一个} 1;END{打印行}' |tac |猛击
示例
$ cat 文件123$ tac 文件 |awk 'NR==1 {行 =$0;下一个} 1;END{打印行}' |战术312
分块:
反向
$ tac 文件321
在最后打印第一项:
$ tac 文件 |awk 'NR==1 {行=$0;下一个} 1;END{打印行}'213
反向:
$ tac 文件 |awk 'NR==1 {行 =$0;下一个} 1;END{打印行}' |战术312
I have a file which contains 3 lines in this order:
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_off.vtran"
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_on.vtran"
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_sanity_dft.vtran"
I have to execute all lines in unix command line one by one in this order:
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_sanity_dft.vtran"
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_off.vtran"
bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_on.vtran"
How can I rearrange & execute all 3 commands using a single command line?
I have tried as you suggest:
line1: echo start
line2: bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_sanity_dft.vtran"
line3: echo hello
line4: bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_off.vtran"
line5: echo bye
line6: bsub -I -q vtran "vtran -scan_pad 0X ../test/pm30_60_224_jtag_bist_full_vector_on.vtran"
line7: echo end
It still execute only line1 & line2. Exit there after..
You can make use of tac
(concatenate and print files in reverse), print the first item at the end and then reverse back:
tac file | awk 'NR==1 {line=$0; next} 1; END{print line}' | tac
Update
Thank you so much fedorqui answering for my first part of question. I can redirect the output of your command to a file & source it from the command line to execute one by one. instead Can you step forward and suggest a way to do it in a single command (without redirecting to a file & source)
You can pipe to bash:
tac file | awk 'NR==1 {line =$0; next} 1; END{print line}' | tac | bash
Example
$ cat file
1
2
3
$ tac file | awk 'NR==1 {line =$0; next} 1; END{print line}' | tac
3
1
2
By pieces:
reverse
$ tac file 3 2 1
print first item at the end:
$ tac file | awk 'NR==1 {line=$0; next} 1; END{print line}' 2 1 3
reverse:
$ tac file | awk 'NR==1 {line =$0; next} 1; END{print line}' | tac 3 1 2
这篇关于如何先移动文件的最后一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!