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.

In Linux if you type cat *, you will get something like this:

line1 from file1
line2 from file1
line1 from file2
line1 from file3
line2 from file3
line3 from file3

What I would like is to display a separator among files. Something like this:
line1 from file1
line2 from file1
XXXXXXXXXXXX
line1 from file2
XXXXXXXXXXXX
line1 from file3
line2 from file3
line3 from file3

Is that easily possible with a one-liner easy to type by heart?

Thanks, Daniele

share|improve this question
add comment

3 Answers

If you're not too fussy about the appearance of the separator:

tail -n +1 *
share|improve this answer
    
This is great! I am surprised how your command is different from tail -n 1 *. I can't either find any mention of the effect of +1 (rathen than 1) in the man page. –  Daniele Aug 19 '10 at 11:21
1  
tail -n X shows the last X lines. tail -n +X starts at line X beginning at 1, i.e., it shows all but the first (X-1) lines. –  Gilles Aug 19 '10 at 11:38
    
Ah, now I can see that in the man page. I overlooked it. Great, thanks a bunch –  Daniele Aug 19 '10 at 11:51
    
Similar solutions are in this article: everythingsysadmin.com/2012/09/unorthodoxunix.html –  TomOnTime Jun 4 at 3:51
add comment

cd /to/your/directory; for each in *; do cat $each; echo "XXXXXXXXXXX"; done

share|improve this answer
    
beat me to it :-) –  Sirex Aug 19 '10 at 11:05
    
Still the solution provided by Gilles is impressively short! –  Janne Pikkarainen Aug 19 '10 at 11:18
add comment
awk 'FNR==1 && NR!=1 {print "XXXXXXXXXXXX"}{print}' *

Or

awk 'FNR==1 {print "XXXXXX" FILENAME "XXXXXX"}{print}' *

Or

awk 'FNR==1 {print "XXXXXX File no. " ++count "XXXXXX"}{print}' *

Using only Bash (no cat):

for file in *; do printf "$(<"$file")\nXXXXXXXXXXXX\n"; done
share|improve this answer
    
+1 for awk! I swear it can do anything... –  brad Dec 19 '10 at 23:29
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.