Save as filter.pl Run as perl filter.pl april_2015.txt
or perl filter.pl april_2015.txt > permanent.txt
or perl filter.pl april_2015.txt may_2015.txt june_2015.txt > permanent.txt
or perl filter.pl *_2015.txt > permanent.txt
I tried code suggested by Aia and its working as per expectations.
However, I would like to run this perl in loop as I have around 830 different patterns like "Permanent".
I tried following
and made following loop.
however, its not working.
I am sure I am doing something wrong.
Kindly suggest.
Moderator's Comments:
Please use CODE tags (not ICODE tags) for full-line and multi-line sample input, output, and code segments.
Last edited by Don Cragun; 12-20-2015 at 03:15 PM..
Reason: Change ICODE tags to CODE tags.
however, its not working.
I am sure I am doing something wrong.
Kindly suggest.
...
The Perl program processes the data file to search for one pattern. Inside the loop, it runs as many times as there are patterns.
So, if your "input_patterns" file has 830 lines, then you process the data file 830 times, searching for one pattern each time!
To give you an analogy, let's say you want to go grocery shopping.
Do you do the following?
(1) Go to grocery store, buy eggs, come back.
(2) Then go to the same grocery store, buy milk, come back.
(3) Then go to the same grocery store, buy meat, come back.
(4) Then go to the same grocery store, buy drinks, come back.
...
I'm sure you see how inefficient this is, yet you're doing something similar in your code.
While this kind of code might work at a small scale (small data file, small pattern file), the inefficiency due to repeated scanning add up at a large scale.
Imagine searching for 10,000 patterns in a million line data file.
Do you want to scan a million line file 10,000 times, looking for one pattern each time?
I tried code suggested by Aia and its working as per expectations.
However, I would like to run this perl in loop as I have around 830 different patterns like "Permanent".
and made following loop.
however, its not working.
I am sure I am doing something wrong.
Kindly suggest.
Moderator's Comments:
Please use CODE tags (not ICODE tags) for full-line and multi-line sample input, output, and code segments.
This is not tested, however, if you want to use the Perl script in that way you need a different modification that what I highlighted in red.
And then you can use the following shell script
Of course, that might be slow due to all the times the binary perl gets called, and the opening, appending and closing of pattern.out. Your mileage may vary there.
Here's a Perl script that might work alone.
Again, it is not tested but you can try with just a portion of your 800 plus patterns input_patterns. It assumes one pattern per line.
Use as perl filter.pl input_patterns april_2015.txt > pattern.out
I am using OSX. I have a multi-mol2 file (text file with coordinates and info for several molecules). An example of two molecules in the file is given below for molecule1 and molecule 2. The total file contains >50,000 molecules.
I would like to extract out and write to another file only the... (2 Replies)
Hi,
Below is my find command
find /opt/app/websphere -name myfolder -perm -600 | wc -l
At time it even takes 20 mins to complete.
my OS is : SunOS mypc 5.10 Generic_150400-09 sun4v sparc SUNW,T5440 (10 Replies)
Hi,
I'm unable to execute the below command completely ; it's not allowing me to type the complete command. It is allowing till "xargs" and i cannot even press enter after that.
I'm using Solaris. Let me know if anything needs to be added so as to execute the complete command. Appreciate... (12 Replies)
Suppose I have a file which contains other file names with some extention .
text file containt
gdsds sd8ef g/f/temp_temp.sum yyeta t/unix.sum
ghfp hrwer h/y/test.text.dat
if then....
I want to get the complete file names, like for above file I should get output as
temp_temp.sum... (4 Replies)
Hi, I'm trying to output all text from the first paragraph in a file that contains a specific string through the last paragraph in that file that contains that string.
Previously, I was outputting just each paragraph with that search string with:
cat in_file | nawk '{RS=""; FS="\n";... (2 Replies)
Hi,
Does anyone know how to make BASH provide a list of possible completions on the first tab, and then start cycling through the possibilites on the next tab?
Right now this is what I have in my .bashrc:
bind "set show-all-if-ambiguous on"
bind \\C-o:menu-complete
This allows... (0 Replies)
hi experts(novice people can stay away as it is no child's game),
i am developing a script which works like recycle bin of windows.
the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to capture... (5 Replies)
hi experts(novice people can stay away as it is no child's game),
i am developing a script which works like recycle bin of windows.
the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to capture... (1 Reply)