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

后端 未结 7 1218
名媛妹妹
名媛妹妹 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:36

    If you want to have fixed n chars per line (don't trust the input file has exact m chars per line) follow this. For the input file with varying number of chars per line:

    $ cat file
    1
    12
    123
    1234
    12345
    

    extend to 10 chars per line.

    $ awk '{printf "%-10s\n", $0}' file | cat -e
    
    1         $
    12        $
    123       $
    1234      $
    12345     $
    

    Obviously change 10 to 200 in your script. Here $ shows end of line, it's not there as a character. You don't need cat -e, here just to show the line is extended.

提交回复
热议问题