Sponsored Content
Full Discussion: Trimming files concurrently
Top Forums Shell Programming and Scripting Trimming files concurrently Post 302153621 by rikxik on Tuesday 25th of December 2007 11:34:35 PM
Old 12-26-2007
Interesting problem. I think it will be quite difficult to handle additional lines in such a fast updating file using sed - after all, sed effectively stores the lines in your file in a buffer and operates on this using pattern & hold space. How can it keep track of new stuff coming in?

You will have to work with something which can seek to the point till which you want to archive & remove that part - DIRECTLY on the ever-changing logfile.

What you can do is reduce the window between these two:

Code:
sed -n "1,${iNumLines}p" $fLog                   # output to <stdout>
sed "1,${iNumLines}d" $fLog > $chTmpDir/log      # remove printed lines

And do it in one shot:

Code:
$ cat data
     1  file:10:no:1011
     2  file:10:file:1011
     3  data:10:say:1011
     4  data:10:data:1011
     5  file:10:file:1011
     6  file:10:file:1011
     7  file:10:file:1011
     8  file:10:file:1011
     9  file:10:file:1011
    10  file:10:file:1011
    11  file:10:file:1011
    12  file:10:file:1011
    13  file:10:file:1011
    14  file:10:file:1011
    15  file:10:file:1011
    16  file:10:file:1011
    17  file:10:file:1011
    18  file:10:file:1011
    19  file:10:file:1011
    20  file:10:file:1011
    21  data:10:say:1011
$ cat sedscr
#!/usr/bin/ksh

iNumLines=10
sed -n "
        # Get the lines to be archived and put on stdout
        1,$iNumLines p
        # Write the rest of (trimmed) data to temporary file. This file can be used to overwrite data.
        $((iNumLines+1)),\$ w data.trimmed
" data
$ sedscr
     1  file:10:no:1011
     2  file:10:file:1011
     3  data:10:say:1011
     4  data:10:data:1011
     5  file:10:file:1011
     6  file:10:file:1011
     7  file:10:file:1011
     8  file:10:file:1011
     9  file:10:file:1011
    10  file:10:file:1011
$ cat data.trimmed
    11  file:10:file:1011
    12  file:10:file:1011
    13  file:10:file:1011
    14  file:10:file:1011
    15  file:10:file:1011
    16  file:10:file:1011
    17  file:10:file:1011
    18  file:10:file:1011
    19  file:10:file:1011
    20  file:10:file:1011
    21  data:10:say:1011

I toyed with the idea of writing directly to data instead of data.trimmed but that obviously doesn't help since the additional lines which came in after sed loaded the file in its buffer will be lost. Basically you can't use sed, ed etc. which operate on a "copy" of the file.

HTH
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing multiple Oracle procedures concurrently

I am using KSH with an OS of AIX Version 5.3. From my shell script, that will be scheduled thorugh a CRON, I need to execute 2 Oracle stored procedures concurrently. If we execute them one at a time, the total execution time takes 4 hours or more. Since they are not dependent on each other and... (6 Replies)
Discussion started by: multidogzoomom
6 Replies

2. Programming

Run 4-processes concurrently

How can i run a back ground process.... I.e for example by using fork() i need to run seperate 4 background processes.. How can send a process to background ??? (9 Replies)
Discussion started by: ugp
9 Replies

3. Programming

how to run socket programme and file management concurrently

hi i have a server socket programme which is running in HP/UX system and then need to add a function about refreshing memory every miniute because the socket programme is blocked , i have no idea about this what should i do thanks (10 Replies)
Discussion started by: benbenpig
10 Replies

4. Shell Programming and Scripting

Running same script multiple times concurrently...

Hi, I was hoping someone would be able to help me out. I've got a Python script that I need to run 60 times concurrently (with the number added as an argument each time) via nightly cron. I figured that this would work: 30 1 * * * for i in $(seq 0 59); do $i \&; done However, it seems to... (4 Replies)
Discussion started by: ckhowe
4 Replies

5. UNIX for Advanced & Expert Users

Trimming the spaces

Hi, How can I remove the unwanted spaces in the line. 123456 789 ABC DEF. - I wanna remove the sapces in this line, I need the output 123456789ABCDEF. Pls help me...... (3 Replies)
Discussion started by: sharif
3 Replies

6. Shell Programming and Scripting

Running function or command concurrently in a bash script

I currently run a script over a vpnc tunnel to back-up my data to a remote server. However for a number of reasons the tunnel often collapses. If I manually restore the tunnel then the whole thing can continue, but I want to add into my script a section whereby while the transfer is taking place,... (8 Replies)
Discussion started by: dj_bridges
8 Replies

7. AIX

Restore and upgrade concurrently

I have serveral servers that are at AIX 6.1 tl4 sp1 and want to move them to new hardware and upgrade them at the same time. Using NIM and sysback images I want to backup the current server with sysback and restore it and upgrade it to AIX 6.1 tl4 sp6 to the new hardware using my NIM server. My... (4 Replies)
Discussion started by: daveisme
4 Replies

8. UNIX for Dummies Questions & Answers

How to run script concurrently

Hi all, I have one script. Its job is to get 1 file from dirA and 1 file from dirB as parameters for another python script. However, there are a lot of files in both dir A and B, so running this scripts really takes a lot of time. So I wonder if there are any ways that I can do this faster,... (6 Replies)
Discussion started by: yoyomano
6 Replies

9. Shell Programming and Scripting

script for Trimming the log files

Dear Gurus, Trimming the alert log files of oracle. I need to write a script retaining last 20 lines of the log files and deleting all the other lines I tried with tail -20 , Please help me how to delete all the other lines, my log files has grown upt to 2G. Thanks in Advance Dave (5 Replies)
Discussion started by: dave234
5 Replies

10. Shell Programming and Scripting

Trimming in between the words

Hi i have a log file P12345_15728710:DEBUG:Begin P12345_15728710:DEBUG:Being P12345_15729310:DEBUG:GetAgen P12345_15726510:DEBUG:end i want to trim this file and i want like this 15728710 15728710 15729310 15726510 i tried sed ..but not working.. sed "s/.*P12345__ \(.*\)... (4 Replies)
Discussion started by: navsan420
4 Replies
LOGSAVE(8)                                                    System Manager's Manual                                                   LOGSAVE(8)

NAME
logsave - save the output of a command in a logfile SYNOPSIS
logsave [ -asv ] logfile cmd_prog [ ... ] DESCRIPTION
The logsave program will execute cmd_prog with the specified argument(s), and save a copy of its output to logfile. If the containing directory for logfile does not exist, logsave will accumulate the output in memory until it can be written out. A copy of the output will also be written to standard output. If cmd_prog is a single hyphen ('-'), then instead of executing a program, logsave will take its input from standard input and save it in logfile logsave is useful for saving the output of initial boot scripts until the /var partition is mounted, so the output can be written to /var/log. OPTIONS
-a This option will cause the output to be appended to logfile, instead of replacing its current contents. -s This option will cause logsave to skip writing to the log file text which is bracketed with a control-A (ASCII 001 or Start of Header) and control-B (ASCII 002 or Start of Text). This allows progress bar information to be visible to the user on the console, while not being written to the log file. -v This option will make logsave to be more verbose in its output to the user. AUTHOR
Theodore Ts'o (tytso@mit.edu) SEE ALSO
fsck(8) E2fsprogs version 1.44.1 March 2018 LOGSAVE(8)
All times are GMT -4. The time now is 05:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy