Print every n lines from a file

后端 未结 4 869
醉话见心
醉话见心 2021-01-21 05:10

I\'m trying to print every nth line from file, but n is not a constant but a variable.

For instance, I want to replace sed -n \'1~5p\'

4条回答
  •  旧巷少年郎
    2021-01-21 05:33

    The point is, you should use double quote " instead of the single one to wrap your sed codes. Variable won't be expanded within single quote. so:

    sed -n "1~${i} p"
    

提交回复
热议问题