Read n lines at a time using Bash

前端 未结 15 2873
难免孤独
难免孤独 2020-11-30 00:25

I read the help read page, but still don\'t quite make sense. Don\'t know which option to use.

How can I read N lines at a time using Bash?

15条回答
  •  旧时难觅i
    2020-11-30 01:08

    Awk is a funny way for this case:

    ~$ cat test.txt 
    tom
    tom@gmail.com
    jack
    jack@gmail.com
    marry
    marry@gmail.com
    gogo
    gogo@gmail.com
    ~$ cat test.txt | awk 'BEGIN{c=1}{a=c;if(a==2){print b" "$0;c=1} if(a==1){b=$0;c=2}}'
    tom tom@gmail.com
    jack jack@gmail.com
    marry marry@gmail.com
    gogo gogo@gmail.com
    

提交回复
热议问题