![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | 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 !! |
Other UNIX.COM Threads 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-29-2007 09:22 PM |
| Removing the first and last lines in a file | naveendronavall | AIX | 1 | 12-29-2007 07:44 PM |
| Removing lines from a file | computersaysno | UNIX for Dummies Questions & Answers | 6 | 11-14-2006 02:50 PM |
| Removing lines within a file | tookers | Shell Programming and Scripting | 3 | 08-22-2006 06:49 AM |
| Removing lines from a file | PradeepRed | Shell Programming and Scripting | 4 | 12-17-2005 02:34 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
removing lines in a too long file
HI, i need to remove about a 3000000 lines in a "too long file", without using vi editor. Im using hp-ux 11.0.
|
| Forum Sponsor | ||
|
|
|
|||
|
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 05:50 AM. Reason: added extra |
|||
| Google UNIX.COM |