Reputation: 20045
Let's assume three files f1,f2,f3 each containing:
header
line1
line2
Now I would like to concatenate all files beginning with "f" but skip the first line in each file - the final result should be:
line1
line2
line1
line2
line1
line2
Upvotes: 6
Views: 7877
Reputation: 20045
find f* -type f -exec tail -n +2 {} \; -exec printf "\n" \; > result
Potential empty lines in result can be taken of by:
grep -v '^$' result > result2
Upvotes: -1
Reputation: 241861
With gnu coreutils:
tail -n+2 f*
Otherwise:
for f in f*; do tail -n+2 "$f"; done
or, if no filename contains a newline character
ls f* | xargs -I{} tail -n+2 {}
All of the above assume that there are no directories whose names start with f
. Otherwise, again assuming no filename contains a newline character, you could use:
ls -p f* | grep -v / | xargs -I{} tail -n+2 {}
Or you could just redirect stderr
to /dev/null
to ignore the error messages from tail
.
Upvotes: 3