![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Removing the first and last lines in a file | naveendronavall | Shell Programming and Scripting | 2 | 12-30-2007 01:22 AM |
| Removing the first and last lines in a file | naveendronavall | AIX | 1 | 12-29-2007 11:44 PM |
| Removing lines from a file | computersaysno | UNIX for Dummies Questions & Answers | 6 | 11-14-2006 06:50 PM |
| Removing lines within a file | tookers | Shell Programming and Scripting | 3 | 08-22-2006 10:49 AM |
| Removing lines from a file | PradeepRed | Shell Programming and Scripting | 4 | 12-17-2005 06:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
found this on unix guru tip. maybe u could try it. gd luck
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= UNIX GURU UNIVERSE UNIX HOT TIP Unix Tip 2429 - August 26, 2005 http://www.ugu.com/sui/ugu/show?tip.today =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= TRIMMING THE LOG Various unix processes can produce fast growing logs that sometimes need to be trimmed instead of deleted, for reference or troubleshooting. And you likely have no desire to edit the files. Here is a handy ksh script that will quickly trim the log so it keeps recent information and lets you keep as many lines as you think you might need. I call it trimlog: #! /bin/sh # trimlog filesize=`cat $1|wc -l` trim=`expr $filesize - $2` if [ $trim -gt 0 ] then sed "1,$trim d" $1 > /tmp/$1 mv /tmp/$1 $1 echo $1 trimmed by $trim lines fi Use it by feeding in the name of the log you want to trim followed by the number of lines you want to keep: # trimlog oracle_listener.log 10000 Of course you can't use it in the /tmp directory. There are probably newer and more efficient ways to do this, but this works. |
|
||||
|
how to code the dir and files trimmed vs giving as arguments
I am brand new to system administration, being a programmer but have no unix experience. Could you please let me know how to perform this same function but instead of giving arguments at command line to do in aprogram so I could put in as a cron job. Greatly appreciate any responses.
Here is something I have found. Is there any way someone could explain to me in 'english' what the code after 'sed' is doing? Also what doesn maxdepth does, have an error that maxdepth is a bad option. cd /var/sam/log || exit 1 for i in $(find . -type f -maxdepth 1) do filename=$(echo $1 | sed 's?^\./\(.*\)?\1?') cp -p $i old/$(date +'%Y%m%d').$filename > $i done exit 0 Last edited by LisaD; 02-04-2008 at 09:50 AM.. Reason: added extra |
![]() |
| Bookmarks |
| Tags |
| awk, awk trim, sed delete line, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|