I found the folowing code that work but it take a long time as i have to open and close the <file2> all the time, is there a optimise way of doing it, maybe using more array?
---------- Post updated at 07:03 PM ---------- Previous update was at 06:55 PM ----------
Hi
tanks a lot, i receive a compilation error with your script
Bareword found where operator expected at ./retest.pl line 22, near "s/,/|/gr"
syntax error at ./retest.pl line 22, near "s/,/|/gr"
Execution of ./retest.pl aborted due to compilation errors
I have a file (status.file) of the form:
valueA 3450
valueB -20
valueC -340
valueD 48
I am tailing a data.file, and need to search and modify a value
in status.file...the tail is:
tail -f data.file | awk '{ print $3, ($NF - $(NF-1)) }'
which will produce lines that look like this:
... (3 Replies)
I have a file (DCN.txt) that has about 35000 lines. It looks like:
10004470028
10005470984
10006470301
10007474812
....
I have several other files (a11.txt, a12.txt, a12_1.txt, a13.txt, etc. about 70, each 100 mb large) that have history records like so:
LINE 10005470984 01/06/2010... (13 Replies)
Hi,
I have a file which got only one column and got some keywords. I have another file where the keywords used in the first file are repeated in the second file.
Now I would like to know how many times each keyword from the first file is repeated in the second file.
Request your help on... (1 Reply)
Dear Friends,
I am looking for a shell script to merge input files into one file .. here is my idea:
1st paramter would be outfile file (all input files content)
read all input files and merge them to input param 1
ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file.
For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Hi everyone,
I am new to Unix and need help writing a script that can ask user for an input, then search that input within a file
I know will have to use the read and grep commands, anyone can give me somewhere to start would help
Task: Write a script to display which volume pool a given... (1 Reply)
Hi Don, this is not homework question. I work for a Credit card company and my development goal this year is to learn Unix. I would love if others can help me get started, thanks.
Hi everyone
I am new to Unix and need help writing a script that can ask user for an input, then search that input... (2 Replies)
Hi I have a CommonTemplateStop.template file . Inside the file i need to replace the variables DepName and CompInsName with the values(Trade and TradeIns) specified in the script. I have written the below .sh script in linux server which will read the .template file and has to replace the 2... (8 Replies)
Hi,
Below is my requirement
File1:
svasjsdhvassdvasdhhgvasddhvasdhasdjhvasdjsahvasdjvdasjdvvsadjhv
vdjvsdjasvdasdjbasdjbasdjhasbdasjhdbjheasbdasjdsajhbjasbjasbhddjb
svfsdhgvfdshgvfsdhfvsdadhfvsajhvasjdhvsajhdvsadjvhasjhdvjhsadjahs
File2:
sdh
hgv
I need a command such that... (8 Replies)
I have a very large file with millions of entries identified by @M. I am using the following script to "extract" entries based on specific strings/patterns:
#!/bin/bash
if ]
then
file=$1
else
echo "Input_file passed as an argument $1 is NOT found."
exit;
fi
MID=(NULL "string-1"... (10 Replies)
Perl::Critic::Policy::InputOutput::RequireBriefOpen(3pm)User Contributed Perl DocumentatioPerl::Critic::Policy::InputOutput::RequireBriefOpen(3pm)NAME
Perl::Critic::Policy::InputOutput::RequireBriefOpen - Close filehandles as soon as possible after opening them.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
One way that production systems fail unexpectedly is by running out of filehandles. Filehandles are a finite resource on every operating
system that I'm aware of, and running out of them is virtually impossible to recover from. The solution is to not run out in the first
place. What causes programs to run out of filehandles? Usually, it's leaks: you open a filehandle and forget to close it, or just wait a
really long time before closing it.
This problem is rarely exposed by test systems, because the tests rarely run long enough or have enough load to hit the filehandle limit.
So, the best way to avoid the problem is 1) always close all filehandles that you open and 2) close them as soon as is practical.
This policy takes note of calls to "open()" where there is no matching "close()" call within "N" lines of code. If you really need to do a
lot of processing on an open filehandle, then you can move that processing to another method like this:
sub process_data_file {
my ($self, $filename) = @_;
open my $fh, '<', $filename
or croak 'Failed to read datafile ' . $filename . '; ' . $OS_ERROR;
$self->_parse_input_data($fh);
close $fh;
return;
}
sub _parse_input_data {
my ($self, $fh) = @_;
while (my $line = <$fh>) {
...
}
return;
}
As a special case, this policy also allows code to return the filehandle after the "open" instead of closing it. Just like the close,
however, that "return" has to be within the right number of lines. From there, you're on your own to figure out whether the code is
promptly closing the filehandle.
The STDIN, STDOUT, and STDERR handles are exempt from this policy.
CONFIGURATION
This policy allows "close()" invocations to be up to "N" lines after their corresponding "open()" calls, where "N" defaults to 9. You can
override this to set it to a different number with the "lines" setting. To do this, put entries in a .perlcriticrc file like this:
[InputOutput::RequireBriefOpen]
lines = 5
CAVEATS
"IO::File->new"
This policy only looks for explicit "open" calls. It does not detect calls to "CORE::open" or "IO::File->new" or the like.
Is it the right lexical?
We don't currently check for redeclared filehandles. So the following code is false negative, for example, because the outer scoped
filehandle is not closed:
open my $fh, '<', $file1 or croak;
if (open my $fh, '<', $file2) {
print <$fh>;
close $fh;
}
This is a contrived example, but it isn't uncommon for people to use $fh for the name of the filehandle every time. Perhaps it's time to
think of better variable names...
CREDITS
Initial development of this policy was supported by a grant from the Perl Foundation.
AUTHOR
Chris Dolan <cdolan@cpan.org>
COPYRIGHT
Copyright (c) 2007-2011 Chris Dolan. Many rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module
perl v5.14.2 2012-06-07 Perl::Critic::Policy::InputOutput::RequireBriefOpen(3pm)