Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have data that looks like this:

01234567
09876544
12345676
34576980

I need to pad this with 11 spaces i.e. my output should look like this:

'           01234567' 
'           09876544'
'           12345676'
'           34576980'

How can I do it using UNIX shell scripting?

share|improve this question
1  
Does your input literally look like this, in one line? How many fields are there? Only two or more? Is this in a text file, and are there more lines than one? What about the spacing between the quotes and the comma, are those to be inserted as well? If you say Unix do you mean UNIX, strictly, or Linux as well? What scripting language? Is Bash okay, or others? Please edit and clarify your question. Maybe you can tell us more about the background, because what you're asking for seems a little contrived. –  slhck Jul 19 '13 at 10:20
1  
There's a live preview how your post will look like afterwards while you're editing. Please use it. –  Daniel Beck Jul 19 '13 at 10:50

1 Answer 1

I'm assuming/guessing that the apostrophes are not supposed to be included in the output.

Standard shell solution, where infile is the file containing the input:

while read i; do printf "%19s\n" "$i"; done < infile

where 19 is the string length per row as they are given (8) plus the wanted padding (11). I'm again guessing that this kind of padding is what you want, and not just prepending 11 spaces to all lines. If this is not the case, you need to give a specific example of how input rows of differing length should be handled.

If the apostrophes were meant to be included:

while read i; do printf "'%19s'\n" "$i"; done < infile
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.