[sclug] Redirecting Tail to a file preserving end of lines
Alex Butcher
lug at assursys.co.uk
Mon Jul 18 13:34:55 UTC 2005
On Mon, 18 Jul 2005, Dickon Hood wrote:
> On Mon, Jul 18, 2005 at 14:18:35 +0100, Sapan Ganguly wrote:
> : Hello, how are you all?
>
> : I've been scratching my head over this one for the past hour or two,
> : how do I take the last line of a bunch of files and put them into a
> : new file? This is what I have been trying -
>
> : # tail --lines=1 --silent *.csv >> newfile
>
> : For some reason the end of lines aren't preserved, newfile ends up
> : being one really long line.
>
> : I've tried a few other ways but I get the same result.
>
> : Any ideas?
>
> for i in *.csv; do tail -1 $i; done > newfile
>
> Works for me.
Alternatively:
tail --lines=1 *.csv | grep -v '==>' >>newfile
The behaviour Sapan describes seems to be triggered by the --silent option.
I'm not sure whether this is a bug, or intentional behaviour.
Dickon's approach looks a bit more robust to me (I don't know if tail can
sometimes insert lines other than those containing '==>').
Best Regards,
Alex.
--
Alex Butcher Brainbench MVP for Internet Security: www.brainbench.com
Bristol, UK Need reliable and secure network systems?
PGP/GnuPG ID:0x271fd950 <http://www.assursys.com/>
More information about the Sclug
mailing list