- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Perl script that detects a problem
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 07:07 AM
тАО12-11-2009 07:07 AM
I need a perl code that scans a huge input file and write to stdout or to another file the 3 following records:
1. The first 32 characters of the previous record.
2. The first 32 characters of the current record.
3. A blank line
The above 3 lines are to be written only on (a combination of all of) the following conditions:
1. The first two characters of the current line are 01, and
2. The first two characters of the previous line are 99, and
3. Positions 3 to 32 are equal in the current line to those of the previous line.
Thanks for the answers.
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 08:27 AM
тАО12-11-2009 08:27 AM
SolutionSee if this fits your needs. Remember, Perl counts zero-relative. Hence when you say "positions 3-32" I translated this to 2-31 zero-relative.
# cat ./filter
#!/usr/bin/perl
use strict;
use warnings;
my $prev = q();
while (<>) {
chomp;
if ( substr( $_, 0, 2 ) eq "01"
and substr( $prev, 0, 2 ) eq "99"
and substr( $_, 2, 31 ) eq substr( $prev, 2, 31 ) )
{
print substr( $prev, 0, 31 ), "\n", substr( $_, 0, 31 ), "\n\n";
}
$prev = $_;
}
1;
...run as:
# ./filter file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 10:29 AM
тАО12-11-2009 10:29 AM
Re: Perl script that detects a problem
It doesnt work. When I put this code in file ├в filter├в and then in the HP-UX command line I type:
./filter tst4
I get:
./filter[3]: use: not found.
./filter[4]: use: not found.
./filter[5]: Syntax error at line 5 : `(' is not expected.
If I put the code in file filter.pl (and remove the first 2 lines) and run as:
perl filter.pl tst4
I get nothing but I know this condition is met in the input file.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 10:48 AM
тАО12-11-2009 10:48 AM
Re: Perl script that detects a problem
> It doesnt work. When I put this code in file ...and then in the HP-UX command line I type:
./filter tst4
I get:
./filter[3]: use: not found.
./filter[4]: use: not found.
./filter[5]: Syntax error at line 5 : `(' is not expected.
Yes, you would get that if you _REMOVED_ the interpreter ("shebang") line: #!/usr/bin/perl . In this case the shell thought that the script was a shell script!
Every script should begin with a line like that. For a shell script you would use something like:
#!/usr/bin/sh
For a Perl script, you would use something like:
#!/usr/bin/perl
Regards!
...JRF....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 11:42 AM
тАО12-11-2009 11:42 AM
Re: Perl script that detects a problem
perl filter.pl tst4
I did try to run it also with the #!/usr/bin/perl line and without the perl, like that:
filter tst4
shouldnt both ways be the same to run a perl script?
I am using POSIX shell.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2009 12:06 PM
тАО12-11-2009 12:06 PM
Re: Perl script that detects a problem
> I had removed the #!/usr/bin/perl only from the file I ran as a parameter to perl, Like that: perl filter.pl tst4
Yes, either of these are equivalent:
# perl filter.pl tst4
# ./filter.pl tst4
[...where the latter starts with an interpreter line...]
#!/usr/bin/perl
If you don't know where Perl lives (or it differs on different servers) you can use this shebang:
#!/usr/bin/env perl
Notice that there is a whitespace after 'env' and before 'perl'.
Regards!
...JRF...