Dear Monks,
I have some oneline-snippets that I have written, I was wondering if they can be presented as-is or I must use also the -n and -p operators...My problem is that I don't know how I can insert these operators in the game!
All the code I am posting below works, it's just that, because I don't really know much regarding oneliners, maybe I can write them more "sophisticated". I don't want to change the code itself, I am rather trying to understand how I can put -n and -p in place...
Example1:
perl -e 'while(<>) {if($_=~/^>/) {print $_;} else {$_=~tr/ATCG/TAGC/;
+print $_;}}' FILE
Example2:
perl -e 'while(<>) {if($_=~/^P00520/) {print $_;}}' FILE
Example3:
perl -e '$count=0; while(<>) {$count++; if($count<=250) {print $_;}}'
+FILE
Example4:
perl -e '$count=0; while(<>) {if($_=~/^>/) {$count++; print ">$count\n
+";} else {print $_;}}' FILE
Example 5:
perl -e 'while(<>) {my $line=$_; if($line!~/^\s+/) {chomp $line; my @s
+plit_line=split(/\s+/, $_); my $wanted_pos=$#split_line-1; print "$sp
+lit_line[0]\t$split_line[$wanted_pos]\n";}}' FILE
Example6:
perl -e 'my $count_serines=0; my $count_positives=0; while(<>) {my $li
+ne=$_; $count_serines++; if($line!~/^\s+/) {chomp $line; my @split_li
+ne=split(/\s+/, $_); my $wanted_pos=$#split_line-1; if($split_line[$w
+anted_pos] eq "*S*") {$count_positives++;}}} print "TOTAL_SERINES: ".
+$count_serines."\t"."POSITIVE_PREDICTIONTS: ".$count_positives."\n";'
+ FILE
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.