How to add 100 spaces at end of each line of a file in Unix

后端 未结 7 1224
名媛妹妹
名媛妹妹 2021-01-12 07:17

I have a file which is supposed to contain 200 characters in each line. I received a source file with only 100 characters in each line. I need to add 100 extra white spaces

7条回答
  •  臣服心动
    2021-01-12 07:28

    Another way in GNU awk using string-manipulation function sprintf.

    awk 'BEGIN{s=sprintf("%-100s", "");}{print $0 s}' input-file > file-with-spaces
    

    A proof with an example:-

    $ cat input-file
    1234jjj hdhyvb 1234jjj
    6789mmm mddyss skjhude
    khora77 koemm  sado666
    nn1004  nn1004 457fffy
    $ wc -c input-file
          92 input-file
    $ awk 'BEGIN{s=sprintf("%-100s", "");}{print $0 s}' input-file > file-with-spaces
    $ wc -c file-with-spaces
          492 file-with-spaces
    

提交回复
热议问题