However, I can not seem to adjust it to account for the last digit in NC_ before the . in bold, may not always be 1 digit as in the case above, it could be 2 digits, as n the case below. In this case I would need to parse out 4 zeros, instead of 5. So my question is I am not sure how to make the condition in italics in the perl command adjust based on the NC_ being 1 or 2 digits? Thank you :).
(1) NC_ + five zeros + 1 digit + "." character => you want that one digit before before "." character
(2) NC_ + four zeros + 2 digits + "." character => you want those two digits before "." character
(3) NC_ + five zeros + 1 character + "." character => you want that one character before "." character
One way to look at it is:
NC_ + a sequence of more than one zeros + sequence of characters that are not zero + "." character
And you want to capture that sequence of non-zero characters before the "." character.
I thought I understood, but not entirely :), but you are correct those are the 3 conditions that are possible. Thank you very much :).
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