Operating System - HP-UX
1834884 Members
2497 Online
110071 Solutions
New Discussion

Re: triming a file contents

 
Nsikan_2
Occasional Advisor

triming a file contents

Hi all,
Could there be an hp unix command to trim specific(range of) contents of a file created without deleting the entire contents of such file?Example, to get rid of contents of a log file generated earlier without getting rid of those generated lately.

Nsikan
7 REPLIES 7
Steve Steel
Honored Contributor

Re: triming a file contents

Hi


depends what you want

look at

split - split a file into pieces

tail - deliver the last part of a file


and script it


steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Jean-Louis Phelix
Honored Contributor

Re: triming a file contents

hi,

I don't really know a pure tool to do it, but concerning log files, sam can do it. Look in routine tasks, system log files. Here you can add your own log files defining a "recommended size" and sam will be able to trim it (to zero, to the recommended size or to a given size).

Regards.
It works for me (© Bill McNAMARA ...)
T G Manikandan
Honored Contributor

Re: triming a file contents

Like

#sed -n '1,10000p' file-name >/tmp/a

which should take first 10000 lines to /tmp/a
Sunil Sharma_1
Honored Contributor

Re: triming a file contents

Hi,

There is no specific command for this but yes you can use sed, tail,head cmd's in scripts and write your own scripts to do this.
sed is good command you can see
man sed
for more info.

Sunil
*** Dream as if you'll live forever. Live as if you'll die today ***
Ramkumar Devanathan
Honored Contributor

Re: triming a file contents

Hi Nsikan,

Add 2 tasks in your crontab -

One will run at midnight every night say - will take a backup copy of the log say /var/logfile and place it in say /tmp/lastnight.log.

Second one will run at say 23:59:59 (if that's possible or just 23:59:00) every night, the following command -

# comm -3 /var/logfile /tmp/lastnight.log > /tmp/today.log

Starting from tomorrow night, the current day's log entries alone will be placed in /tmp/today.log. Fine tune this if you wish - the above times are just examples, with no great Sys Admin knowledge.

Of course, you would like to know more about the comm utility - so "man comm".

HTH.

- ramd.
HPE Software Rocks!
Michael Steele_2
Honored Contributor

Re: triming a file contents

For a file size = 278761580 bytes.

split -b 56m source_file dest
split -b 55752k ... ...
split -b 55752316 ... ...

Also a line unit of measure:

http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/B9106-90007/B9106-90007_top.html&con=/hpux/onlinedocs/B9106-90007/00/03/325-con.html&toc=/hpux/onlinedocs/B9106-90007/00/03/325-toc.html&searchterms=split&queryid=20030428-053714
Support Fatherhood - Stop Family Law
Steve Steel
Honored Contributor

Re: triming a file contents

Hi


Of all these things the cron to move the files to a daily version and then use find with mtime +2 or so to delete the old ones will work most simly.Cron means you never forget to run it.

What files are you talkin about.


steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)