Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file manipulation

Status
Not open for further replies.

minus0

Programmer
Feb 20, 2003
73
US
Is there a way of deleting some lines from a file without actually opening it? I have some logs that I need to go over for analysis but I need to look at the entries only after a particular time say 11:30pm so I wish to delete all the entries from the log that are prior to 11:30pm. Its not just one file that I need to look at so manually deleting the entries is not really an option.

Appreciate any inputs
 
Hi minus0
can you give the file contents so that I can give the exact command syntax ...I have couple of doubts like:
11.30pm line number is constant or changing every time...
And I want to see the location of that word in your file..
I will give sed command syntax that will serve your purpose.
please reply ASAP

sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
Hi minus0

If you have strictly the 11:30pm line in your file ...you can delete the all entries in your log file prior to 11:30pm
as follows.If you provide me with your log file as I requested in my previous post ...it will be more understandable...anyway ...try this...

#sed -n '/11.30pm/,$p <inFile>outFile

Now cat outFile ...


sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
Hi minus

There is a typo(single closing quote missing) in my previous post...
please read as
sed -n '/11.30pm/,$p' <inFile>outFile



sushveer
IBM certified specialist-p-series AIX5L System Administration
AIX/SOLARIS/WEBSPHERE-MQ/TIVOLI Administrator
 
Hello Sushveer,

I wouldn't know the line number and the reason I mentioned 11:30pm - the Applications I work on are restarted every night at 11:30pm. I would see something like

Timestamp: Application started

I will try out your sed command tomorrow and let you know the result - thanks for your help
 
Sushveer,

Your tip helped me a lot - thanks
 
minus0,

Why don't you set up a cron job to rotate the logs around 11:30pm when the apps restarted. Here's a script we use for some log files that are constant (it originally came from Netscape log rotate);

DATE=`date +%y%m%d`
LOGDIR=/usr/local/logs
LOGS='app1.log app2.log app3.log app4.log'

(cd ${LOGDIR}
for file in ${LOGS}
do
if [ -f &quot;$file&quot; ]
then
mv $file $file.${DATE}
fi
done
)

# Clean up older log files
find ${LOGDIR}/app1.log.* -mtime +14 -exec rm {} \;
find ${LOGDIR}/app2.log.* -mtime +7 -exec rm {} \;
find ${LOGDIR}/app3.log.* -mtime +3 -exec rm {} \;
find ${LOGDIR}/app4.log.* -mtime +14 -exec rm {} \;

And here's the cron entry;

31 11 * * * . /usr/local/sysadm/bin/log_roll.sh > /dev/null 2>&1

Good luck


 
Thanks for the suggestion about setting up a cron job - I do have a cron job set up and it works too ;-) but I needed to analyze some of the old logs - thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top