Sponsored Content
Top Forums Shell Programming and Scripting Removing lines from a file being used by another process using SHELL script Post 302705499 by nikhil8 on Tuesday 25th of September 2012 03:39:11 AM
Old 09-25-2012
Removing lines from a file being used by another process using SHELL script

Hi All,

Need a small help in writing a shell script which can delete a few lines from a file which is currently being used by another process.

File gets appended using tee -a command due to which its size is getting increased.
Contents like :
Code:
[INFO] 25/09/2012 05:18 Run ID:56579677-1

My requirement is to remove lines which are more than 1 month old...
for this i will cut month from the line i.e. 09 and backtrack to fetch the previous value i.e. 8
and remove all lines from top till the row fetched...

Query is can i remove the lines in the same file ? (what if another process comes to write in that file using tee -a)..

Thanks,
Nik

Last edited by Scrutinizer; 09-25-2012 at 04:39 AM.. Reason: code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can i know file using another process on lunix shell script?

hi all, I did RedHat OS. How can i know myfile using another process on lunix shell script? Have you got any suggestions? (1 Reply)
Discussion started by: Tlg13team
1 Replies

2. Shell Programming and Scripting

help removing characters for output file in shell script

hi i'm new to shell scripts and have a small problem i am running a batch converter that returns all flash .flv files in a directory and create a png image from each one the problem i have is the $1 variable , its ok on the first call but on the secound call $1.png , i have extra... (1 Reply)
Discussion started by: wingchun22
1 Replies

3. Shell Programming and Scripting

Removing the entire file contents using unix shell script.

I need to remove the entire file contents in file using the shell script. Actually the grap -v command will create one more file and it occupy the space also. I need to remove the entire file contents without creating new file using the shell scripting. Please help me. (5 Replies)
Discussion started by: praka
5 Replies

4. Shell Programming and Scripting

Script for Removing Lines from File / Blocking internet connection

Hey all. I am trying to write some scripts and need some assistance. One: I already have a script that appends lines to a file. I need a script that will remove those lines from that file, and have no idea how to go about doing this. Just need the command (if any) that can remove lines. ... (2 Replies)
Discussion started by: Dysruption
2 Replies

5. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

6. Shell Programming and Scripting

What is the function of the following lines at the top of a shell script file: Directory and Script?

The file starts like this: Directory: <path to the script> Script: <script fife name> #!bin/ksh ##Comments <actual script> What is the use of the first two lines in the script? What if I save the file without them? What will be the effect? They are not comments. Im very new to this,... (4 Replies)
Discussion started by: remytom
4 Replies

7. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

8. Shell Programming and Scripting

Shell script to report file size, pid and also kill the process

Hi All, Looking for a quick LINUX shell script which can continuously monitors the flle size, report the process which is creating a file greater than certain limit and also kill that process. Can someone please help me on this? (4 Replies)
Discussion started by: vasavimacherla
4 Replies

9. UNIX for Beginners Questions & Answers

By pass a process in a Shell Script on file size

I wish to by pass a process if the file is over a certain size? not sure this makes sense current bit of the script below #if we are bypAssing the OCR if ; then echo Bypassing HOTFOLDER OCR HOT_FOLDER_DIR=$BATCH_POST_OCR_DIR; potential change below? would this work would I need... (1 Reply)
Discussion started by: worky
1 Replies

10. Shell Programming and Scripting

Script to process a list of items and uncomment lines with that item in a second file

Hello, I have a src code file where I need to uncomment many lines. The lines I need to uncomment look like, C CALL l_r(DESNAME,DESOUT, 'Gmax', ESH(10), NO_APP, JJ) The comment is the "C" in the first column. This needs to be deleted so that there are 6 spaces preceding "CALL".... (7 Replies)
Discussion started by: LMHmedchem
7 Replies
Tee(3pm)						User Contributed Perl Documentation						  Tee(3pm)

NAME
IO::Tee - Multiplex output to multiple output handles SYNOPSIS
use IO::Tee; $tee = IO::Tee->new($handle1, $handle2); print $tee "foo", "bar"; my $input = <$tee>; DESCRIPTION
"IO::Tee" objects can be used to multiplex input and output in two different ways. The first way is to multiplex output to zero or more output handles. The "IO::Tee" constructor, given a list of output handles, returns a tied handle that can be written to. When written to (using print or printf), the "IO::Tee" object multiplexes the output to the list of handles originally passed to the constructor. As a shortcut, you can also directly pass a string or an array reference to the constructor, in which case "IO::File::new" is called for you with the specified argument or arguments. The second way is to multiplex input from one input handle to zero or more output handles as it is being read. The "IO::Tee" constructor, given an input handle followed by a list of output handles, returns a tied handle that can be read from as well as written to. When written to, the "IO::Tee" object multiplexes the output to all handles passed to the constructor, as described in the previous paragraph. When read from, the "IO::Tee" object reads from the input handle given as the first argument to the "IO::Tee" constructor, then writes any data read to the output handles given as the remaining arguments to the constructor. The "IO::Tee" class supports certain "IO::Handle" and "IO::File" methods related to input and output. In particular, the following methods will iterate themselves over all handles associated with the "IO::Tee" object, and return TRUE indicating success if and only if all associated handles returned TRUE indicating success: close truncate write syswrite format_write formline fcntl ioctl flush clearerr seek The following methods perform input multiplexing as described above: read sysread readline getc gets eof getline getlines The following methods can be used to set (but not retrieve) the current values of output-related state variables on all associated handles: autoflush output_field_separator output_record_separator format_page_number format_lines_per_page format_lines_left format_name format_top_name format_line_break_characters format_formfeed The following methods are directly passed on to the input handle given as the first argument to the "IO::Tee" constructor: input_record_separator input_line_number Note that the return value of input multiplexing methods (such as "print") is always the return value of the input action, not the return value of subsequent output actions. In particular, no error is indicated by the return value if the input action itself succeeds but subsequent output multiplexing fails. EXAMPLE
use IO::Tee; use IO::File; my $tee = new IO::Tee(*STDOUT, new IO::File(">tt1.out"), ">tt2.out"); print join(' ', $tee->handles), " "; for (1..10) { print $tee $_, " " } for (1..10) { $tee->print($_, " ") } $tee->flush; $tee = new IO::Tee('</etc/passwd', *STDOUT); my @lines = <$tee>; print scalar(@lines); AUTHOR
Chung-chieh Shan, ken@digitas.harvard.edu COPYRIGHT
Copyright (c) 1998-2001 Chung-chieh Shan. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perlfunc, IO::Handle, IO::File. perl v5.12.3 2001-03-10 Tee(3pm)
All times are GMT -4. The time now is 04:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy