Transpose rows into column in unix

后端 未结 7 2170
耶瑟儿~
耶瑟儿~ 2021-02-10 18:36

I have input file which is given below

Input file

10,9:11/61432568509
118,1:/20130810014023
46,440:4/GTEL
10,9:11/61432568509
118,1:/20130810014023
46,44         


        
7条回答
  •  温柔的废话
    2021-02-10 19:11

    Using awk:

    $ awk 'ORS=(NR%3==0)?"\n":","' inputfile
    10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
    10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
    

    EDIT: As commented by sudo_O and Ed Morton, the following variant is more portable:

    $ awk 'ORS=(NR%3?",":RS)' inputfile
    10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
    10,9:11/61432568509,118,1:/20130810014023,46,440:4/GTEL
    

提交回复
热议问题