Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

#!/bin/bash
for ERR in `find -name "error.log"`;
do
    echo -e "---- LOG: $ERR ----";
    tail -n 5 $ERR;
done;

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

2 Answers

up vote 5 down vote accepted

Pipe your tail command through sed:

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

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

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.