Yacob
Yacob

Reputation: 525

Append different number of spaces at the end of a string

I want to add different number of spaces after a string:

I have used

echo "444rrrr" | sed 's/$/     /' 

This adds 5 space after "444rrrr". Since I do not know the number of spaces that I have to add before hand. Is there away to tell the "sed" command to vary the spaces that I want to append at the end of each string ?

Thank you in advance.

Upvotes: 0

Views: 185

Answers (1)

Kent
Kent

Reputation: 195029

see this, note the _ just for example, since spaces are not easy to see here. you can change it into space.

kent$  n=5                                                       

kent$  echo "444rrr"|awk -vn="$n" '{for(i=1;i<=n;i++)$0=$0 "_"}1'
444rrr_____

Upvotes: 1

Related Questions