LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-11-2006, 06:19 AM   #16
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31

Actually I don't understand your problem with sed. An example:
Code:
$ echo "line 1\nline 2\nline 3" > theFile.txt
$
$ cat theFile.txt
line 1
line 2
line 3
$ sed -i '1d' theFile.txt
$
$ cat theFile.txt
line 2
line 3
???

Last edited by Flesym; 04-11-2006 at 06:30 AM.
 
Old 04-11-2006, 06:20 AM   #17
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
Flesym did a good suggestion with using two files ... but:
to delete from line 1 until delimiter \n (i think):
Code:
sed -i '1,/\\n$/d' theFile.txt
assuming the \n is always at the end of a line.

Last edited by muha; 04-11-2006 at 06:21 AM.
 
Old 04-11-2006, 06:22 AM   #18
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
[double Post, sorry]
 
Old 04-11-2006, 06:42 AM   #19
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
Quote:
Another more efficient way would be to use two (or even more) files: Begin by filling the first file until it reaches 1MB; then open the second file and keep on writing to this until it is full. Now blank the first file again and log to this for the next 1MB and so on... This way you can review at least your desired last 1MB and won't have to worry about performance, because you only append and truncate (both are cheap file operations), so there is no buffer and no additional string operation needed. But of course this has to fit into your software design
iam using this method only right now but i got review comments from my manager tat , after i fill up the 2 files,i create a new one and delete the old one, but the concept is jus the insertion of a single record will be followed by the loss of 1MB of data (though we have 1MB more at hand) still it sounds a bit odd to him, thats the reason i am trying other methods. and my system generates a lot of messages at a very short interval of time .
 
Old 04-11-2006, 06:54 AM   #20
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
Quote:
sed -i '1,/\\n$/d' theFile.txt
this wipes out the entire file
 
Old 04-11-2006, 07:05 AM   #21
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
true, sorry It tries to find the largest hit so that would be the entire file ...
 
Old 04-11-2006, 07:07 AM   #22
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
ya gud thing i tried it on a prototype and not on my actual thing
 
Old 04-11-2006, 07:14 PM   #23
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Why not use logrotate(8) ?
 
Old 04-11-2006, 10:47 PM   #24
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
Quote:
Why not use logrotate(8) ?
ya i thot of tat too ... logrotate removes old files after a regular time interval right (say once in a day )? so incase if there are no log files being generated in my system , then all my log files become older by time so they may be deleted but i may need them for debugging(1MB of log data is needed all the time) , so because of this reason i dint opt for it , but may be u cud correct me if am wrong, exactly how does logrorate operate ?
 
Old 04-11-2006, 10:56 PM   #25
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
logrotate does anything you want, it won't delete anything unless you tell it to. Typically you move the files to another dir eg an archive dir & gzip them.
 
Old 04-12-2006, 01:14 AM   #26
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
finally i have settled in this concept :
Quote:
i will keep 5 files each of 200KB and i have a circular buffer for 200kb and my msgs goto tat buffer and from it i write each file after the buffer gets filled so it will b a 200kb write each time to the file rather than writing file for every msg. after filling up 5 files i delete the first and create a new one and rename the others and will carry on doing this continuously
so how does this concept sound ? any issues tat any of u cud find ?

Last edited by Deepak Inbasekaran; 04-12-2006 at 01:34 AM.
 
Old 04-12-2006, 05:04 AM   #27
Flesym
Member
 
Registered: Aug 2005
Location: Germany
Distribution: Ubuntu, Debian
Posts: 189

Rep: Reputation: 31
I wouldn't wait with the writing until the buffer is full. This may cause that you will loose the last 200kb during a crash. There is nothing wrong with writing some text to the end of a file. At least as long this won't happen several thousand times per second. The rest sounds good.
 
Old 04-12-2006, 05:24 AM   #28
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
ya the problem is my system is generating 1000s of msgs at a short time so i prefer the buffer approach rather than writing each time to the file . also i plan to have some code tat writes off the data in the buffer to a file before the crash.
 
Old 04-12-2006, 06:54 PM   #29
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
If you can predict the crash like that, you can probably prevent it ....
 
Old 04-12-2006, 11:54 PM   #30
Deepak Inbasekaran
Member
 
Registered: Apr 2006
Location: India
Distribution: Red Hat Linux release 9 (Shrike)
Posts: 44

Original Poster
Rep: Reputation: 15
thatsy i have a small buffer size so tat the data lost wont be much.
 
  


Reply

Tags
sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



All times are GMT -5. The time now is 09:12 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration