The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-10-2005
Goodfella Goodfella is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 1
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.
  #2 (permalink)  
Old 11-10-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
look into using either one of the standard Unix utilities: sed, ex, awk etc....
if you elaborate on the removal criteria, you might get a more detailed answer.
  #3 (permalink)  
Old 11-10-2005
akrathi akrathi is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 41
ex - data << end-of-script
# give your removiing creteria over here
#this will delete line number 2

2d
wq
end-of-script
this deletes the second line
  #4 (permalink)  
Old 11-10-2005
ashterix ashterix is offline
Registered User
  
 

Join Date: Nov 2005
Location: cyberjaya
Posts: 85
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.
  #5 (permalink)  
Old 02-04-2008
LisaD LisaD is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 1
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
Closed Thread

Bookmarks

Tags
awk, awk trim, sed delete line, trim, trim awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0