Sponsored Content
Top Forums Shell Programming and Scripting Perl to run different parser based on digit Post 302993286 by durden_tyler on Wednesday 8th of March 2017 11:27:04 AM
Old 03-08-2017
Quote:
Originally Posted by cmccabe
I thought I understood, but not entirely ..., but you are correct those are the 3 conditions that are possible. ...
Code:
perl -ne 'next if $. == 1;
    if(/.*del([A-Z]+)ins([A-Z]+).'s/NC_0+(.*?)\..*/$1/; print')   # indel
{
        print join("\t", $3, $4, $5, $1, $2), "\n";
}
           ' out_position.txt > out.txt
Unknown regexp modifier "/N" at -e line 2, at end of line
Unknown regexp modifier "/C" at -e line 2, at end of line
Unknown regexp modifier "/_" at -e line 2, at end of line
Unknown regexp modifier "/0" at -e line 2, at end of line
syntax error at -e line 2, near "(."
Execution of -e aborted due to compilation errors.

My example was for illustrative purpose, so you can adapt the regex to suit your code. You simply copy-pasted it in your code. It won't work that way.

1) Why put single-quotes within single-quotes? Your Perl code starts after "-ne" and goes up to "out_position.txt". Your Perl code is within single quotes. If you put something in single quotes inside it, how will the perl interpreter understand it?

2) Why use the s/// operator inside the "if" branch? What is Perl supposed to do if you use s/// operator inside the "if" branch? Check the documentation: s - perldoc.perl.org

3) Why use the "print" function inside the "if" branch? What is Perl supposed to do if you do that?

4) Where is the closing forward-slash ("/") character in the "if" branch? If you do not demarcate the pattern you want to search, how will Perl know it? Check the syntax of the "if" branch: if - perldoc.perl.org
This User Gave Thanks to durden_tyler For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

xml parser in perl

hi all i want to read xml file in perl i am using XML::Simple for this. i am not getting how to read following file removing xml file due to some reason (1 Reply)
Discussion started by: zedex
1 Replies

2. Shell Programming and Scripting

Perl XML:Parser help

I am very new to XML. Really I have an excel file that I am trying to read w/ Perl on a Linux machine. I don't have a mod for reading excel files so I have to convert the excel file to xml to be able to read it. I can read the file and everything is ok except...the Number style is being dropped... (0 Replies)
Discussion started by: vincaStar
0 Replies

3. Shell Programming and Scripting

xml-parser with perl

Hello I want to write an xml- parser with perl an i use the libary XML::LibXML. I have a problem with the command getElementsByTagName. If there is an empty tag, the getElementsByTagName method returns a NodeList of length zero. how can i check if this is a nodelist of lenght zero?? i... (1 Reply)
Discussion started by: trek
1 Replies

4. Shell Programming and Scripting

perl config parser

Hello. Can anybody help me with some sub on perl that can parse config like this: %CFG ( 'databases' => { 'db1' => 'db_11', 'db_12', 'db_13', 'db2' => 'db_21', 'db_22', 'db_23' } 'datafiles' => { 'datadir1' => 'datadir_11', 'datadir_12', 'datadir2' =>... (4 Replies)
Discussion started by: drack
4 Replies

5. Shell Programming and Scripting

Split large file based on last digit from a column

Hello, What's the best way to split a large into multiple files based on the last digit in the first column. input file: f 2738483300000x0y03772748378831x1y13478378358383x2y23743878383802x3y33787828282820x4y43748838383881x5y5 Desired Output: f0 3738483300000x0y03787828282820x4y4 f1... (9 Replies)
Discussion started by: alain.kazan
9 Replies

6. Shell Programming and Scripting

Where to find 64-bit based perl module like XML::Parser::Expat?

Q: Where to get a 64 bit Expat.so? I run a perl script and got this error: Can't load '/usr/perl5/vendor_perl/5.8.4/i86pc-solaris-64int/auto/XML/Parser/Expat/Expat.so' for module XML:parser::Expat: ld.so.1:myPerl: fatal:... (0 Replies)
Discussion started by: lilili07
0 Replies

7. Programming

Parser - multiple in Perl

Dear Perl Experts, Could some body help me to find the solution for my problem below: Input file: ----------- THE-0 tsjp THE-32 tsjp THE-64 tsjp Output desired: --------------- THE-0&&-31 tsjp THE-32&&-63 tsjp THE-64&&-95 tsjp Note: 31 = 0+31, (2 Replies)
Discussion started by: askari
2 Replies

8. Shell Programming and Scripting

Update perl code with parser

The below perl code imports the data in the attached document. However, I can not seem to update the perl code to include a parser like in the desired tab of that document. Thank you :). Most of the data for the parse is included in the document except for the gene and RNA which can is... (0 Replies)
Discussion started by: cmccabe
0 Replies

9. UNIX for Beginners Questions & Answers

Cut first value after underscore and replace first two digit with zero in perl

Like I have below string XX_49154534_491553_201_122023_D XX_49159042_491738_201_103901_D and the expected output would be 0154534 0159042 XX and 49 can be dynamic. (1 Reply)
Discussion started by: nadeemrafikhan
1 Replies
CheckDigits::MXX_005(3pm)				User Contributed Perl Documentation				 CheckDigits::MXX_005(3pm)

NAME
CheckDigits::MXX_005 - compute check digits for ESR9 (CH) SYNOPSIS
use Algorithm::CheckDigits; $esr = CheckDigits('esr9'); if ($esr->is_valid('123456786')) { # do something } $cn = $esr->complete('12345678'); # $cn = '123456786' $cd = $esr->checkdigit('123456786'); # $cd = '6' $bn = $esr->basenumber('123456786'); # $bn = '12345678' DESCRIPTION
ALGORITHM 1. Digits are processed left to right. For the first digit applies the balance is 0. 2. The new balance is taken from the balance table according to the current balance (row) and the digit (column). 3. The check digit is the difference from the last balance to 10 taken modulo 10. METHODS is_valid($number) Returns true only if $number consists solely of numbers and the last digit is a valid check digit according to the algorithm given above. Returns false otherwise, complete($number) The check digit for $number is computed and concatenated to the end of $number. Returns the complete number with check digit or '' if $number does not consist solely of digits and spaces. basenumber($number) Returns the basenumber of $number if $number has a valid check digit. Return '' otherwise. checkdigit($number) Returns the checkdigit of $number if $number has a valid check digit. Return '' otherwise. EXPORT None by default. AUTHOR
Mathias Weidner, <mathias@weidner.in-bad-schmiedeberg.de> SEE ALSO
perl, CheckDigits, www.pruefziffernberechnung.de. perl v5.10.0 2008-05-17 CheckDigits::MXX_005(3pm)
All times are GMT -4. The time now is 11:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy