Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

say I have the following bash script that finds all error.logs gives them a header and then tails 5 lines below it..

for ERR in `find -name "error.log"`;
    echo -e "---- LOG: $ERR ----";
    tail -n 5 $ERR;

I would like to have it output like so:

---- LOG: foo/error.log ----
    [error ....]
    [error ....]
---- LOG: foo/error.log ----
    [error ....]
    [error ....]
---- LOG: foo/error.log ----
    [error ....]
    [error ....]

where the tail'd section is indented some amount of characters (e.g. 4 or whatever a tab character is)

How would I indent that specific section out output?

share|improve this question
up vote 6 down vote accepted

Pipe your tail command through sed:

tail -n 5 $ERR | sed -e 's/^/    /'
share|improve this answer

There are many ways. One might be to simply pipe through sed or awk and add some space.

cat syslog | sed -e 's/^/    /'
cat syslog | sed -e 's/^/\t/'
share|improve this answer

Your Answer


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.