<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: script to trim the file size base on size in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180822#M162871</link>
    <description>For example:&lt;BR /&gt;&lt;BR /&gt;$tail -c 15 a.sh&lt;BR /&gt;&lt;BR /&gt;While trying same with head, I am finding some error.&lt;BR /&gt;&lt;BR /&gt;sks</description>
    <pubDate>Tue, 03 Feb 2004 01:28:51 GMT</pubDate>
    <dc:creator>Sanjay Kumar Suri</dc:creator>
    <dc:date>2004-02-03T01:28:51Z</dc:date>
    <item>
      <title>script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180814#M162863</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;As above, i don't know how to write the script to trim the file size base on size. Means, let say i want to trim the file from 200mb to 50mb. Any guidance?&lt;BR /&gt;&lt;BR /&gt;Rgs&lt;BR /&gt;&lt;BR /&gt;Cheng Wee&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Feb 2004 22:35:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180814#M162863</guid>
      <dc:creator>Cheng Wee</dc:creator>
      <dc:date>2004-02-02T22:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180815#M162864</link>
      <description>Hi Cheng Wee,&lt;BR /&gt;&lt;BR /&gt;Actually the file itself to trim down size must be edited to lessen the size of it. you can use vi then delete some unnecessary lines .&lt;BR /&gt;vi filename&lt;BR /&gt;then type dd to lines not so important.&lt;BR /&gt;then save the file by typing wq! then enter.&lt;BR /&gt;&lt;BR /&gt;Ferdie</description>
      <pubDate>Mon, 02 Feb 2004 22:53:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180815#M162864</guid>
      <dc:creator>Ferdie Castro</dc:creator>
      <dc:date>2004-02-02T22:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180816#M162865</link>
      <description>Hi Cheng,&lt;BR /&gt;&lt;BR /&gt;You can do it using SAM. &lt;BR /&gt;&lt;BR /&gt;If you are planning to trim the system related log files then the best method is to use sam.&lt;BR /&gt;&lt;BR /&gt;From SAM --&amp;gt; Routine Tasks --&amp;gt; System Log Files&lt;BR /&gt;&lt;BR /&gt;From here either you can trim the file to recommended or manually specified size.&lt;BR /&gt;&lt;BR /&gt;Also you can add custom files to the list. Add whichever file that you want to reduce the size to the list from the Actions menu. Then follow the same procedure for trimming it.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Karthik S S</description>
      <pubDate>Mon, 02 Feb 2004 23:13:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180816#M162865</guid>
      <dc:creator>Karthik S S</dc:creator>
      <dc:date>2004-02-02T23:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180817#M162866</link>
      <description>So is there anyway we can simulate what the sam do using script?</description>
      <pubDate>Tue, 03 Feb 2004 00:55:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180817#M162866</guid>
      <dc:creator>Cheng Wee</dc:creator>
      <dc:date>2004-02-03T00:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180818#M162867</link>
      <description>SAM does something like this:&lt;BR /&gt;&lt;BR /&gt;cp syslog.log OLDsyslog.log&lt;BR /&gt;tail -20 OLDsyslog.log &amp;gt; syslog.log&lt;BR /&gt;&lt;BR /&gt;At least, that's what might do what you want.&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Feb 2004 01:11:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180818#M162867</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2004-02-03T01:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180819#M162868</link>
      <description>I am not sure if you can call this SAM area from with in a script. Is the type of the file that you want to trim is Ascii?? if yes may be we can try to write a script clubbing "wc -l", "du filename" and sed/tail.&lt;BR /&gt;&lt;BR /&gt;We can roughly relate the size of the file with respect to the number of lines. Let us assume that the file size is 10MB and the number of lines are 50000. If you want to trim the size to 5MB then we know that we need approximately delete 25000 lines from the top. Then using tail redirect only the last 25000 lines to a new file and then move it back to overwrite the large original file. We can also use sed for this.&lt;BR /&gt;&lt;BR /&gt;-Karthik S S</description>
      <pubDate>Tue, 03 Feb 2004 01:16:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180819#M162868</guid>
      <dc:creator>Karthik S S</dc:creator>
      <dc:date>2004-02-03T01:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180820#M162869</link>
      <description>So what if i want to trim it according to size instaed of line number, is there anyway?</description>
      <pubDate>Tue, 03 Feb 2004 01:16:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180820#M162869</guid>
      <dc:creator>Cheng Wee</dc:creator>
      <dc:date>2004-02-03T01:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180821#M162870</link>
      <description>head and tail has -c option which can give desired output.&lt;BR /&gt;&lt;BR /&gt;sks</description>
      <pubDate>Tue, 03 Feb 2004 01:23:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180821#M162870</guid>
      <dc:creator>Sanjay Kumar Suri</dc:creator>
      <dc:date>2004-02-03T01:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180822#M162871</link>
      <description>For example:&lt;BR /&gt;&lt;BR /&gt;$tail -c 15 a.sh&lt;BR /&gt;&lt;BR /&gt;While trying same with head, I am finding some error.&lt;BR /&gt;&lt;BR /&gt;sks</description>
      <pubDate>Tue, 03 Feb 2004 01:28:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180822#M162871</guid>
      <dc:creator>Sanjay Kumar Suri</dc:creator>
      <dc:date>2004-02-03T01:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180823#M162872</link>
      <description>Even head is working as the following example shows:&lt;BR /&gt;&lt;BR /&gt;$head -c -n2 a.sh&lt;BR /&gt;&lt;BR /&gt;where -c: The quantity of output is measured in bytes.&lt;BR /&gt;&lt;BR /&gt;sks</description>
      <pubDate>Tue, 03 Feb 2004 01:32:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180823#M162872</guid>
      <dc:creator>Sanjay Kumar Suri</dc:creator>
      <dc:date>2004-02-03T01:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180824#M162873</link>
      <description>with head you need to give as,&lt;BR /&gt;&lt;BR /&gt;head -c -n (byte count) filename&lt;BR /&gt;&lt;BR /&gt;-Karthik S S</description>
      <pubDate>Tue, 03 Feb 2004 01:32:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180824#M162873</guid>
      <dc:creator>Karthik S S</dc:creator>
      <dc:date>2004-02-03T01:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180825#M162874</link>
      <description>If you really,really want a log file to end up an exact number of bytes try something like this.  It creates a new file with an extention of ".trim" that should be the exact size you require.  You can modify it if you like to delete he original.  I have only done a quick test and it doesn't do any error checking so be careful.&lt;BR /&gt; &lt;BR /&gt;run it with "logtrunk.pl &lt;FILENAME&gt; &lt;NEWSIZE in="" bytes=""&gt;&lt;BR /&gt; &lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;($FILENAME,$NEWSIZE)=@ARGV;&lt;BR /&gt;$SIZE=(stat $FILENAME)[7];&lt;BR /&gt;$LOSEAMOUNT=$SIZE-$NEWSIZE;&lt;BR /&gt;&lt;BR /&gt;open FILE, "&amp;lt;$FILENAME";&lt;BR /&gt;open TRIMEDFILE, "&amp;gt;$FILENAME"."trim";&lt;BR /&gt;read FILE, $WASTE, $LOSEAMOUNT;&lt;BR /&gt;while(&lt;FILE&gt;){&lt;BR /&gt;        print TRIMEDFILE;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;close FILE;&lt;BR /&gt;close TRIMEDFILE;&lt;/FILE&gt;&lt;/NEWSIZE&gt;&lt;/FILENAME&gt;</description>
      <pubDate>Tue, 03 Feb 2004 02:02:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180825#M162874</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2004-02-03T02:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180826#M162875</link>
      <description>There is another command split which can give desired result.&lt;BR /&gt;&lt;BR /&gt;$split -b 200 file_name&lt;BR /&gt;&lt;BR /&gt;Check man pages for more options.&lt;BR /&gt;&lt;BR /&gt;sks</description>
      <pubDate>Tue, 03 Feb 2004 02:04:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180826#M162875</guid>
      <dc:creator>Sanjay Kumar Suri</dc:creator>
      <dc:date>2004-02-03T02:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180827#M162876</link>
      <description>Cheng&lt;BR /&gt;&lt;BR /&gt;You can't use "tail" for large files, because it only works in a 20K buffer.&lt;BR /&gt;&lt;BR /&gt;You also need to be careful if applications are  holding files open - you don't want to rename the original file, copy the last 50MB back to the orignal file name, then delete the oriignal file, because the applications will continue writing to the original (now "deleted") file, and continue to eat up disk space.</description>
      <pubDate>Tue, 03 Feb 2004 04:00:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180827#M162876</guid>
      <dc:creator>Alan Turner</dc:creator>
      <dc:date>2004-02-03T04:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180828#M162877</link>
      <description>Well, to do exactly what you asked, use Perl's truncate function -- on OS's that support the truncate system call -- and HP-UX does:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;if ($#ARGV &amp;gt;= 1)&lt;BR /&gt;  {&lt;BR /&gt;    $fname = "+&amp;lt; $ARGV[0]";&lt;BR /&gt;    open FH1, $fname or die "Can't open $ARGV[0]\n";&lt;BR /&gt;    truncate(FH1,$ARGV[1]);&lt;BR /&gt;    close FH1;&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;For example,&lt;BR /&gt;truncate.pl myfile 5000&lt;BR /&gt;would open myfile and then truncate it to exactly 5000 bytes.&lt;BR /&gt;&lt;BR /&gt;This is very useful in cases where you are short of space and cannot copy the contents to another file.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 03 Feb 2004 09:23:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180828#M162877</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-02-03T09:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180829#M162878</link>
      <description>Since none of the typical file trimming techniques for log files aren't what you are looking for, I'll assume this is a non-ascii work file that has to be a precise size.&lt;BR /&gt; &lt;BR /&gt;You could use "dd" with the count= parameter.&lt;BR /&gt; &lt;BR /&gt;dd bs=1024 count=50k if=oldfile of=newfile&lt;BR /&gt; &lt;BR /&gt;This will created newfile at precisely 50mb. Then you could "mv newfile oldfile" to replace the original file.&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Tue, 03 Feb 2004 09:35:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180829#M162878</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2004-02-03T09:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180830#M162879</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;Sorry for the late reply, been very busy yesterday. Just to clarify one thing, is really work on ascii file, i asking about size is because i wonder how sam can trim log file until recommended size. I interesting with the perl script that can truncate without need to copy the file to another place first and also the concern on not delete the original file. I will look at this in more detail. &lt;BR /&gt;&lt;BR /&gt;Appreciate all replies.&lt;BR /&gt;&lt;BR /&gt;Rgs &lt;BR /&gt;&lt;BR /&gt;Cheng Wee</description>
      <pubDate>Tue, 03 Feb 2004 19:45:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180830#M162879</guid>
      <dc:creator>Cheng Wee</dc:creator>
      <dc:date>2004-02-03T19:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180831#M162880</link>
      <description>Alan Turner   wrote on Feb 3, 2004 09:00:47 GMT &lt;BR /&gt;&amp;gt;-------------------------------------------------------------------------------&lt;BR /&gt;&amp;gt;Cheng&lt;BR /&gt;&lt;BR /&gt;&amp;gt;You can't use "tail" for large files, &amp;gt;because it only works in a 20K buffer.&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;Nah... that would be soooo seventies!&lt;BR /&gt;You can wag that tail well over 20K...&lt;BR /&gt;Don't know what the limit (if any) is.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;$ uname -a&lt;BR /&gt;HP-UX  B.11.23 U ia64 &lt;BR /&gt;$ tail -1000 kc.log &amp;gt; x&lt;BR /&gt;$ ls -l x&lt;BR /&gt;  39059 Feb  4 00:53 x&lt;BR /&gt;$ tail -c -10000 kc.log &amp;gt; x&lt;BR /&gt;$ ls -l x&lt;BR /&gt;  10000 Feb  4 00:49 x&lt;BR /&gt;$ tail -c -50000 kc.log &amp;gt; x&lt;BR /&gt;$ ls -l x&lt;BR /&gt;  50000 Feb  4 00:49 x&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Feb 2004 01:01:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180831#M162880</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-02-04T01:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180832#M162881</link>
      <description>That is interesting, but my server is still running on hp-ux b.11.00 and it is not working. So is this a new feature on newer O.S?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Feb 2004 01:20:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180832#M162881</guid>
      <dc:creator>Cheng Wee</dc:creator>
      <dc:date>2004-02-04T01:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: script to trim the file size base on size</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180833#M162882</link>
      <description>Hein / Cheng&lt;BR /&gt;&lt;BR /&gt;11.11 seems to be limited to 20K:&lt;BR /&gt;&lt;BR /&gt;cd /var/adm/sw&lt;BR /&gt;wc -l swagent.log&lt;BR /&gt;8955 swagent.log&lt;BR /&gt;tail -4000 swagent.log &amp;gt; /tmp/at&lt;BR /&gt;ll /tmp/at&lt;BR /&gt;  (size = 20480)&lt;BR /&gt;wc -l /tmp/at&lt;BR /&gt;564 /tmp/at&lt;BR /&gt;tail -c -45000 swagent.log &amp;gt; /tmp/atc&lt;BR /&gt;ll /tmp/atc&lt;BR /&gt;  (size = 20480)&lt;BR /&gt;&lt;BR /&gt;also see WARNINGS in 'man tail'&lt;BR /&gt;&lt;BR /&gt;By the way - regarding Clay's response (note his use of "exactly") - this will truncate the file, i.e. chop off the end, and may not be what you want if you would prefer to retain the newest, rather than oldest, records.&lt;BR /&gt;&lt;BR /&gt;One possible approach would be:&lt;BR /&gt;a)calculate the file size (ls -s gives it in blocks)&lt;BR /&gt;b) work out how many blocks to skip&lt;BR /&gt;c) use dd skip=&lt;ANSWER from="" b=""&gt; to copy the last 50 MB to a temp file (logtemp)&lt;BR /&gt;d) cat logtemp &amp;gt; logfile&lt;BR /&gt;e) rm logtemp&lt;BR /&gt;&lt;BR /&gt;The trouble with this approach is that records added after step c) may be lost, or mingle in with the records being copied in from logtemp.&lt;BR /&gt;&lt;BR /&gt;I had a slightly related problem to solve  a few months ago, but in my case, the log file was the captured output from a script which spawned a couple of hundred sub-processes.  What I did was to replace "&amp;gt;&amp;gt;log" with "|script.pl"  where script.pl managed the log file (log and log.OLD) after a certain  number of lines had been written.&lt;/ANSWER&gt;</description>
      <pubDate>Wed, 04 Feb 2004 05:11:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-to-trim-the-file-size-base-on-size/m-p/3180833#M162882</guid>
      <dc:creator>Alan Turner</dc:creator>
      <dc:date>2004-02-04T05:11:50Z</dc:date>
    </item>
  </channel>
</rss>

