Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have data that looks like this:


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
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
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

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

You can use Ex-editor (Vi), either by changing the file in-place:

ex -s +"%s@^@    @" -cwq foo.txt

or by parsing the standard input and print it into standard output:

cat foo.txt | ex -s +"%s@^@    @" +%p -cq! /dev/stdin
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .