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

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

    Just in case you are looking for a bash solution,

    while IFS=  read -r line
        do
        printf "%s%100s\n" "$line" 
    done < file > newfile
    

    Test

    Say I have a file with 3 lines it it as

    $ wc -c file
          16 file
    $ wc -c newfile
         316 newfile
    

    Original Answer

    spaces=$(echo {1..101} | tr -d 0-9)
    while read line
        do
        echo -e "${line}${spaces}\n" >> newfile
    done < file
    

提交回复
热议问题