gpt4 book ai didi

unix - 如何先移动文件的最后一行?

转载 作者:行者123 更新时间:2023-12-01 09:57:30 26 4
gpt4 key购买 nike

我有一个按以下顺序包含 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 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

它仍然只执行第 1 行和第 2 行。之后退出那里..

最佳答案

您可以使用 tac (反向连接并打印文件),在末尾打印第一项,然后反向返回:

tac file | awk 'NR==1 {line=$0; next} 1; END{print line}' | tac

更新

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)



您可以通过管道连接到 bash:
tac file | awk 'NR==1 {line =$0; next} 1; END{print line}' | tac | bash

例子
$ cat file
1
2
3

$ tac file | awk 'NR==1 {line =$0; next} 1; END{print line}' | tac
3
1
2

按件数:
  • 逆转
    $ tac file
    3
    2
    1
  • 最后打印第一项:
    $ tac file | awk 'NR==1 {line=$0; next} 1; END{print line}'
    2
    1
    3
  • 逆转:
    $ tac file | awk 'NR==1 {line =$0; next} 1; END{print line}' | tac
    3
    1
    2
  • 关于unix - 如何先移动文件的最后一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22833588/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com