Command to get nth line of STDOUT

前端 未结 12 1789
闹比i
闹比i 2020-12-07 07:39

Is there any bash command that will let you get the nth line of STDOUT?

That is to say, something that would take this

$ ls -l
-rw-r--r--@ 1 root  wh         


        
12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 08:04

    Hmm

    sed did not work in my case. I propose:

    for "odd" lines 1,3,5,7... ls |awk '0 == (NR+1) % 2'

    for "even" lines 2,4,6,8 ls |awk '0 == (NR) % 2'

提交回复
热议问题