Gaurav Parek
Gaurav Parek

Reputation: 327

Padding a files with n number of spaces at the end of the line

I have a file which looks like below format. I want to padd it with spaces at the end of line.

File1.txt

Steve Smith
Thomas Muller
Tim Cook
Bill Gates

I have used below command but it is not giving me the desired output,it is spliting as

Steve 
Smith 

and then giving output.

while read line; do printf "%-20s\n" $line; done < file1.txt

The desired output for the above files is as below.s is the spaces added for padding the each line.

Steve Smithssssssssssssssssssssssssssss
Thomas Mullerssssssssssssssssssssssssss
Tim Cooksssssssssssssssssssssssssssssss
Bill Gatessssssssssssssssssssssssssssss

Upvotes: 1

Views: 100

Answers (1)

anubhava
anubhava

Reputation: 785058

Quote the variable line and better to use read -r:

while read -r line; do printf "%-20s\n" "$line"; done < file1.txt

Test:

while read -r line; do printf "%-20s\n" "$line"; done < file1.txt | cat -vte
Steve Smith         $
Thomas Muller       $
Tim Cook            $
Bill Gates          $

Upvotes: 2

Related Questions