10-15-2008
grep problem in perl
Hi,
I'm writing one perl script to select only a number part from a line. These lines looks as:
raj born on 20080201 at delhi
result for the equation [(A+B) * (B*C)] is (886005)
peter get married on 20031230
Maria born on 20080201 at paris
my output file should only contains the numbers, by removing the duplicate.
i.e, for the above line, my output file should contains only below lines.
20080201
886005
20031230
I've writen the code as below, seem to be some problem in 'grep' part.
#!/usr/bin/perl
use File::Find;
use strict;
my $in_file = "/software/app//input_file.txt";
my $out_file = "/software/app//output_file.txt";
my @outLines;
my $line;
my $cur_num;
open (FILE, $in_file ) or die "Cannot open file: $!";
open( OUTFILE, "> " . $out_filename ) or die "Cannot open file: $!";
while ( $line = <FILE> ) {
$cur_num =~ grep( /[0-9]/ , $line);
push(@outLines, $cur_num);
}
print ( OUTFILE @outLines );
close FILE;
close ( OUTFILE );
undef ( @outLines );
Any help would be much appreciated.
Much Regards / Lokesha
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I'm using perl to do a grep of each line in a vendor file and find its occurrences in a specific directory. Any values found is saved in @dir.
.....(file opened, etc.)
....
while ($line=<FILE>){
@dir = `grep $line * `;
}
It's the specific usage of the system grep that I'm having... (7 Replies)
Discussion started by: gavineq
7 Replies
2. Shell Programming and Scripting
OK here's the situation:
I have got these lines which I have got to parse.
If the line contains a particular string and any element from a previously defined array I need to take that particular line and do some further processing.
if ((grep(/$_/,$1)) && (grep($pattern,@myarr)))
{
#Do... (2 Replies)
Discussion started by: King Nothing
2 Replies
3. Shell Programming and Scripting
Hello
I want to grep a line from a file saved in some directory.
Can anyone please correct the code below:
#!/usr/bin/perl -w
$file = "/home/output.txt"
$grep_line = "closing zip for topic";
`grep $grep_line* $file`; (1 Reply)
Discussion started by: sureshcisco
1 Replies
4. Shell Programming and Scripting
Hi guys,
I'm trying to learn grep and map and having a little problem.
Let's say I have a file which contains:
Apple: abcdcabdadddbac
I want to replace any combinations of three of abcd, thus when I do this:
print grep {s/{3}/X/g} <F>; # will do the subtitution fine, output XXXX
... (1 Reply)
Discussion started by: new bie
1 Replies
5. Shell Programming and Scripting
I have to do grep -v in a perl script. I want to exclude blank lines and lines having visitor.
#grep -v visitor abc.txt |grep '.'
file:abc.txt
1340 not booked 16D:D9 tourist 8
1341 not booked 16C:D4 tourist 25
1342 not booked 16D:C4 visitor 7
1343 not booked 01C:D9 visitor 6
1344... (4 Replies)
Discussion started by: dynamax
4 Replies
6. Shell Programming and Scripting
Hi All i have this script that uses glob to look in /var/log/messages.*
my @messagefiles = glob "/var/log/messages.*";
and the code that uses it is this
grep { /NVRM: Xid/ } @messages)
but this spits out this
/var/log/messages-20111030:Oct 25 13:43:04 brent kernel: NVRM:... (10 Replies)
Discussion started by: ab52
10 Replies
7. Web Development
Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect.
Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is
redirected to welcome page.
My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies
8. Shell Programming and Scripting
Hi,
Can anybody let me know how this grep will work.
The input and output is not known.
Also can you give me the details of any link where i can find clearly about grep
Thanks in advance (1 Reply)
Discussion started by: irudayaraj
1 Replies
9. Shell Programming and Scripting
hello Everyone i am a newbie.
i have a file which contains the following
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe: o:\portsrc\spg\system_1\i486_nt\advapps\TK-2\objmt\winclockmtq.lib
E:\gtmproj\script\i486_nt\obj\check_geomtools.exe:... (12 Replies)
Discussion started by: Rashid Khan
12 Replies
10. UNIX for Dummies Questions & Answers
I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore.
Here is what 's happening:
* I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies
LEARN ABOUT DEBIAN
lpssumelm
LPSSUMELM(1) User Commands LPSSUMELM(1)
NAME
lpssumelm - remove superfluous summations from an LPS
SYNOPSIS
lpssumelm [OPTION]... [INFILE [OUTFILE]]
DESCRIPTION
Remove superfluous summations from the linear process specification (LPS) in INFILE and write the result to OUTFILE. If INFILE is not
present, stdin is used. If OUTFILE is not present, stdout is used.
OPTIONS
OPTION can be any of the following:
-c, --decluster
first decluster disjunctive conditions
--timings[=FILE]
append timing measurements to FILE. Measurements are written to standard error if no FILE is provided
Standard options:
-q, --quiet
do not display warning messages
-v, --verbose
display short intermediate messages
-d, --debug
display detailed intermediate messages
--log-level=LEVEL
display intermediate messages up to and including level
-h, --help
display help information
--version
display version information
AUTHOR
Written by Jeroen Keiren.
REPORTING BUGS
Report bugs at <http://www.mcrl2.org/issuetracker>.
COPYRIGHT
Copyright (C) 2012 Technische Universiteit Eindhoven.
This is free software. You may redistribute copies of it under the terms of the Boost Software License
<http://www.boost.org/LICENSE_1_0.txt>. There is NO WARRANTY, to the extent permitted by law.
SEE ALSO
See also the manual at <http://www.mcrl2.org/mcrl2/wiki/index.php/User_manual/lpssumelm>.
lpssumelm mCRL2 toolset 201202.0 (Release) April 2012 LPSSUMELM(1)