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

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

    If you use Bash, you can still use sed, but use some readline functionality to keep you from manually typing 100 spaces (see manual for "Readline arguments").

    You start typing normally:

    sed 's/$/
    

    Now, you want to insert 100 spaces. You can do this by prepending hitting the space bar with a readline argument to indicate that you want it to happen 100 times, i.e., you manually enter what would look like this as a readline keybinding:

    M-1 0 0 \040
    

    Or, if your meta key is the alt key: Alt+1 00Space

    This inserts 100 spaces, and you get

    sed 's/$/                                                                                                    /' filename
    

    after typing the rest of the command.

    This is useful for working in an interactive shell, but not very pretty for scripts – use any of the other solutions for that.

    0 讨论(0)
提交回复
热议问题