delete first 100 lines rather than zero out of file


 
Thread Tools Search this Thread
Operating Systems Solaris delete first 100 lines rather than zero out of file
# 1  
Old 11-09-2007
delete first 100 lines rather than zero out of file

Hi experts,

in my solaris 9 the file- /var/adm/messeages growin too first. by 24 hours 40MB. And always giving the below messages--

bash-2.05# tail -f messages
Nov 9 16:35:38 ME1 last message repeated 1 time
Nov 9 16:35:38 ME1 ftpd[16392]: [ID 476795 daemon.error] wtmpx /var/adm/wtmpx No such file or directory
Nov 9 16:35:38 ME1 last message repeated 1 time
Nov 9 16:35:38 ME1 ftpd[16393]: [ID 476795 daemon.error] wtmpx /var/adm/wtmpx No such file or directory
Nov 9 16:35:38 MEMM1 last message repeated 1 time
---
i then tried with #touch wtmpx. Although the above messages stops but wtmpx grows more faster than file 'messages'. so i again delete 'wtmpx'. For your information this SUN server uses for various types of FTP everyminutes. So, far i know 'wtmpx' files logs the user access. that is why it grows too fast.
I now plan to adjust a script in crontab which will delete first 100 lines from messages after 2/3 days.
But i don't know how to implement the script. Could anyone help me??

Cheers
purple
# 2  
Old 11-09-2007
The following command will delete the first 100 lines from your wtmpx file:

$ sed '1,100d' wtmpx

However, if your wtmpx file grows by 40MB's every 24 hours I reckon 100 lines will not make much of a difference. Do a cat wtmpx |wc -l to count the lines and then decide how many lines you should delete to shrink the file size sufficiently.
# 3  
Old 11-09-2007
Hi soliberus,
I tried to delete first 100 lines of file messages with command # sed '1,100d' messages. But it is not working. Please see below.
bash-2.05# cat messages |wc -l
36948
bash-2.05# sed '1,100d' messages
bash-2.05# cat messages |wc -l
36949
bash-2.05#

And about 'wtmpx'- the file is not understanble to me Smilie. So, i plan to delete only lines from 'messages'
bash-2.05# tail -f wtmpx
bgwftpftp10010'G4)192.168.210.35bgwftpftp10010G4)192.168.210.35bgwftpftp10012'G4)192.168.210.35bgwft pftp10011'4)192.168.210.42bgwftpftp10012G4)192.168.210.35bgwftpftp100114)192.168.210.42bgwftpftp1001 3'G4*192.168.210.35bgwftpftp10013G4*192.168.210.35bgwftpftp10014'G4+192.168.210.42bgwftpftp10014G4+1 92.168.210.42bgwftpftp10015'G4+192.168.210.37bgwftpftp10015G4+192.168.210.37bgwftpftp10016' G4+192.168.210.40bgwftpftp10016'G4+192.168.210.40bgwftpftp10017'!G4+192.168.210
bash-2.05# cat wtmpx |wc -l
13
Though it shows only 13 lines and lines are growing slowly but File size is growing to much fast.
# 4  
Old 11-12-2007
Ooops, I didn't give you the full script.

It should look something like this:

sed '1,100d' messages > messages.tmp
cat messages.tmp > messages
rm message.tmp


I'm sure this is not the most effective way of truncating a file, but it works.
# 5  
Old 11-13-2007
Quote:
Originally Posted by soliberus

It should look something like this:

sed '1,100d' messages > messages.tmp
cat messages.tmp > messages
rm message.tmp

Hi buddy, many thanks for the script. It should work.
# 6  
Old 11-13-2007
if ' -i ' option is available in the sed you are using ( GNU sed )

use it

Code:
sed -i '1,100d' file

just the above would do
# 7  
Old 11-14-2007
delete first 100 lines rather than zero out of file

Hi all, i told you i m getting mainly prob with frequently growing 2 files /var/adm/messages OR /var/adm/wtmpx.
I got a solution for overgrowing wtmpx. Below is the line need to put in cronjob. it will empty wtmpx file after every 30 minutes.

30 * * * * su - root -c "cat /dev/null > /var/adm/wtmpx" > /dev/null 2>&1

I get it from sun solaris 8. Although i am using solaris 9 but hope line should work it also . However, can anyone tell me what is the value here "root -c" and "2>&1"??

Quote:
Originally Posted by thepurple
Hi soliberus,
I tried to delete first 100 lines of file messages with command # sed '1,100d' messages. But it is not working. Please see below.
bash-2.05# cat messages |wc -l
36948
bash-2.05# sed '1,100d' messages
bash-2.05# cat messages |wc -l
36949
bash-2.05#

And about 'wtmpx'- the file is not understanble to me Smilie. So, i plan to delete only lines from 'messages'
bash-2.05# tail -f wtmpx
bgwftpftp10010'G4)192.168.210.35bgwftpftp10010G4)192.168.210.35bgwftpftp10012'G4)192.168.210.35bgwft pftp10011'4)192.168.210.42bgwftpftp10012G4)192.168.210.35bgwftpftp100114)192.168.210.42bgwftpftp1001 3'G4*192.168.210.35bgwftpftp10013G4*192.168.210.35bgwftpftp10014'G4+192.168.210.42bgwftpftp10014G4+1 92.168.210.42bgwftpftp10015'G4+192.168.210.37bgwftpftp10015G4+192.168.210.37bgwftpftp10016' G4+192.168.210.40bgwftpftp10016'G4+192.168.210.40bgwftpftp10017'!G4+192.168.210
bash-2.05# cat wtmpx |wc -l
13
Though it shows only 13 lines and lines are growing slowly but File size is growing to much fast.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete Some Lines from File

Hi, I have a txt document having a format like this: DATA1 | DATA2 | DATA3 | 23-JAN-20 23:41:34 DATA1 | DATA2 | DATA3 | 23-JAN-20 23:41:32 DATA1 | DATA2 | DATA3 | 23-JAN-20 23:41:30 ... DATA1 | DATA2 | DATA3 | 23-JAN-20 22:35:31 DATA1 | DATA2 | DATA3 | 23-JAN-20 22:30:34 DATA1 | DATA2 |... (1 Reply)
Discussion started by: gc_sw
1 Replies

2. Shell Programming and Scripting

Delete 40 lines after every 24 lines from a file

Hello, I have file of more than 10000 lines. I want to delete 40 lines after every 20 lines. e.g from a huge file, i want to delete line no from 34 - 74, then 94 - 134 etc and so on. Please let me know how i can do it. Best regards, (11 Replies)
Discussion started by: nehashine
11 Replies

3. UNIX for Advanced & Expert Users

Delete first 100 lines from a BIG File

Hi, I need a unix command to delete first n (say 100) lines from a log file. I need to delete some lines from the file without using any temporary file. I found sed -i is an useful command for this but its not supported in my environment( AIX 6.1 ). File size is approx 100MB. Thanks in... (18 Replies)
Discussion started by: unohu
18 Replies

4. UNIX for Advanced & Expert Users

In a huge file, Delete duplicate lines leaving unique lines

Hi All, I have a very huge file (4GB) which has duplicate lines. I want to delete duplicate lines leaving unique lines. Sort, uniq, awk '!x++' are not working as its running out of buffer space. I dont know if this works : I want to read each line of the File in a For Loop, and want to... (16 Replies)
Discussion started by: krishnix
16 Replies

5. UNIX for Dummies Questions & Answers

How get only required lines & delete the rest of the lines in file

Hiiii I have a file which contains huge data as a.dat: PDE 1990 1 9 18 51 28.90 24.7500 95.2800 118.0 6.1 0.0 BURMA event name: 010990D time shift: 7.3000 half duration: 5.0000 latitude: 24.4200 longitude: 94.9500 depth: 129.6000 Mrr: ... (7 Replies)
Discussion started by: reva
7 Replies

6. Shell Programming and Scripting

How to delete lines in a file that have duplicates or derive the lines that aper once

Input: a b b c d d I need: a c I know how to get this (the lines that have duplicates) : b d sort file | uniq -d But i need opossite of this. I have searched the forum and other places as well, but have found solution for everything except this variant of the problem. (3 Replies)
Discussion started by: necroman08
3 Replies

7. Solaris

delete first 100 lines from a file

I have a file with 28,00,000 lines of rows in this the first 80 lines will be chunks . I want to delete the chunks of 80 lines. I tried tail -f2799920 filename. is there any efficient way to do this. Thanks in advance. (7 Replies)
Discussion started by: salaathi
7 Replies

8. UNIX for Dummies Questions & Answers

Delete same lines out of file.

hello... I have a file with a list of filepaths in it, like so: delMe.txt (files to be deleted) ./root/index.php ./root/language/se/home.inc.php ./root/language/pl/home.inc.php Now here's what I'm trying to do. I want any lines in the above file (delMe.txt) to be deleted out of the... (3 Replies)
Discussion started by: jzacsh
3 Replies

9. Shell Programming and Scripting

Please help to delete lines in a file

Dear All, I m trying to delete two lines at a time in file called 123.txt. Im using sed and based on line numbers i m deleting it and writing it to another file. Follwing i have done. cat 123.txt | sed '1,5 d' > new I want to delete line no 1 and 5 at a time, for that i m using... (6 Replies)
Discussion started by: naree
6 Replies

10. UNIX for Dummies Questions & Answers

delete all lines in file

how can i delete all lines in file by using "vi" ? (6 Replies)
Discussion started by: strok
6 Replies
Login or Register to Ask a Question