syntax error input "end of line without line continuation" - pine-script-v5

TDUp = TD - ta.valuewhen(TD < TD[1], TD, 1 )
plotshape(TDUp==7?true:na,style=shape.triangledown, color=color.red,
text="7",
textcolor=color.red, location=location.abovebar)
plotshape(TDUp==8?true:na,style=shape.triangledown, color=color.red,
text="8",
textcolor=color.red, location=location.abovebar)
Says syntax error at line 6 which is the 1st photshape word

add spaces after using second line in code
TDUp = TD - ta.valuewhen(TD < TD[1], TD, 1 )
plotshape(TDUp==7?true:na,style=shape.triangledown, color=color.red,
text="7",
textcolor=color.red, location=location.abovebar)
plotshape(TDUp==8?true:na,style=shape.triangledown, color=color.red,
text="8",
textcolor=color.red, location=location.abovebar)

Related

How to count the numbers of elements in parts of a text file using a loop in Perl?

I´m looking for a way to create a script in Perl to count the elements in my text file and do it in parts. For example, my text file has this form:
ID Position Potential Jury agreement NGlyc result
(PART 1)
NP_073551.1_HCoV229Egp2 23 NTSY 0.5990 (8/9) +
NP_073551.1_HCoV229Egp2 62 NTSS 0.7076 (9/9) ++
NP_073551.1_HCoV229Egp2 171 NTTI 0.5743 (5/9) +
...
(PART 2)
QJY77946.1_NA 20 NGTN 0.7514 (9/9) +++
QJY77946.1_NA 23 NTSH 0.5368 (5/9) +
QJY77946.1_NA 51 NFSF 0.7120 (9/9) ++
QJY77946.1_NA 62 NTSS 0.6947 (9/9) ++
...
(PART 3)
QJY77954.1_NA 20 NGTN 0.7694 (9/9) +++
QJY77954.1_NA 23 NTSH 0.5398 (5/9) +
QJY77954.1_NA 51 NFSF 0.7121 (9/9) ++
...
(PART N°...)
Like you can see the ID is the same in each part (one for PART 1, other to PART 2 and then...). The changes only can see in the columns Position//Potential//Jury agreement//NGlyc result Then, my main goal is to count the line with Potential 0,7 >=.
With this in mind, I´m looking for output like this:
Part 1:
1 (one value 0.7 >=)
Part 2:
2 (two values 0.7 >=)
Part 3:
2 (two values 0.7 >=)
Part N°:
X numbers of values 0.7 >=
This output tells me the number of positive values (0.7 >=) for each ID.
The pseudocode I believe would be something like this:
foreach ID in LIST
foreach LINE in FILE
if (ID is in LINE)
... count the line ...
end foreach LINE
end foreach ID
I´m looking for any suggestion (for a package or script idea) or comment to create a better script.
Thanks! Best!
To count the number of lines, for each part, that match some condition on a certain column, you can just loop over the lines, skip the header, parse the part number, and use an array to count the number of lines matching for each part.
After this you can just loop over the counts recorded in the array and print them out in your specific format.
#!/usr/bin/perl
use strict;
use warnings;
my $part = 0;
my #cnt_part;
while(my $line = <STDIN>) {
if($. == 1) {
next;
}elsif($line =~ m{^\(PART (\d+)\)}) {
$part = $1;
}else {
my #cols = split(m{\s+},$line);
if(#cols == 6) {
my $potential = $cols[3];
if(0.7 <= $potential) {
$cnt_part[$part]++;
};
};
};
};
for(my $i=1;$i<=$#cnt_part;$i++){
print "Part $i:\n";
print "$cnt_part[$i] (values 0.7 <=)\n";
};
To run it, just pipe the entire file through the Perl script:
cat in.txt | perl count.pl
and you get an output like this:
Part 1:
1 (values 0.7 <=)
Part 2:
2 (values 0.7 <=)
Part 3:
2 (values 0.7 <=)
If you want to also display the counts into words, you can use Lingua::EN::Numbers (see this program ) and you get an output very similar to the one in your post:
Part 1:
1 (one values 0.7 <=)
Part 2:
2 (two values 0.7 <=)
Part 3:
2 (two values 0.7 <=)
All the code in this post is also available here.

How to break a long code line into multiple lines in NetLogo?

In Python, we break a long line of code into multiple code lines with backslash like this.
a = 5
b = 11
print(str(a) + " plus " + \
str(b) + " is " + \
str(a + b))
# prints "5 plus 11 is 16"
How do we do that in NetLogo?
NetLogo doesn't care about multiple lines except for comments (the comment marker ; only lasts to the end of the line). All of these are the same:
to testme
; single line
let a 25 print a
; command per line
let b 20
print b
; unreadable
let
c
15
print
c
end

Regex match to extract data between first ( and last ) incase the data contains brackets?

I am trying to extract data from a string of text using Powershell. The data I need is between the first and last bracket. What I have so far appears to work but doesn't work if the data itself contains a close bracket...
$MyText = "BT /F3 8.999 Tf 0 0 0 rg 407.446 TL 64.368 772.194 Td (\(TESTJulia\) Julia's Test Company) Tj T* ET"
[regex]::match($MyText,'(?<=\().+?(?=\))')
Is this what you want?
$MyText = "BT /F3 8.999 Tf 0 0 0 rg 407.446 TL 64.368 772.194 Td (\(TESTJulia\) Julia's Test Company) Tj T* ET"
$match = [regex]::Match($MyText,'\(+?(.*)\)')
Write-Host $match.Captures.groups[1].value
Output:
\(TESTJulia\) Julia's Test Company
Regex explanation (courtesy Regex101.com):
\(+? matches the character ( literally (case sensitive)
+? Quantifier — Matches between one and unlimited times, as few times as possible, expanding as needed (lazy)
1st Capturing Group (.*)
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\) matches the character ) literally (case sensitive)
here's a slightly different way to get there ... [grin]
it depends on the td ( and ) tj being always there, but it works with your sample data.
$InStuff = "BT /F3 8.999 Tf 0 0 0 rg 407.446 TL 64.368 772.194 Td (\(TESTJulia\) Julia's Test Company) Tj T* ET"
$InStuff -match 'td \((.+)\) tj .+$'
$Matches[1]
output ...
\(TESTJulia\) Julia's Test Company
Why not remove the lazy quantifier? This will make it greedy so that it grabs as many characters as it can unti it hits the lookahead.
PS>$MyText = "BT /F3 8.999 Tf 0 0 0 rg 407.446 TL 64.368 772.194 Td (\(TESTJulia\) Julia's Test Company) Tj T* ET"
PS>[regex]::match($MyText,'(?<=\().+(?=\))')
Groups : {0}
Success : True
Name : 0
Captures : {0}
Index : 55
Length : 35
Value : \(TESTJulia\) Julia's Test Company

Hello, how do I copy text and paste it into another line in notepad?

how do I copy text and paste it into another line in notepad?
need to copy the text between "0;" and ";"
then paste it in the desired location.
How do I do that?
tried using regular expressions, but could not.
example:
filename new.txt
Start
1- 0; Text 1 ;
2- line 1
3- line 1
4- line 3
5-
6- 0; Text 2 ;
7- line 1
8- line 1
9- line 3
10-
11- 0; Text 3 ;
12- line 1
13- line 1
14- line 3
end
change to:
filename new.txt
Start
1- 0; Text 1 ;
2- line 1
3- line 1
4- line 3 Text 1
5-
6- 0; Text 2 ;
7- line 1
8- line 1
9- line 3Text 2
10-
11- 0; Text 3 ;
12- line 1
13- line 1
14- line 3 Text 3
end
Not a question for Stack Overflow.
Select the text by clicking and dragging, making the desired portion blue.
Right-click the selection.
Click "Copy."
Move the cursor to the desired position, and right-click again.
Click "Paste."
Alternatively, you can press Ctrl and C to copy, and Ctrl and V to past.

How to print all lines except the line before a pattern in file using awk

How can we do this with awk?
Input file
Line 1
Line 2
####PATTERN####### (Line 3)
Line 4
Line 5
Line 6
####PATTERN####### (line 7)
Line 8
####PATTERN####### (Line 9)
etc..
output file
Line 1
Line 3
Line 4
Line 5
Line 7
Line 9
sed '$!N;s/.*####PATTERN####### \(.*\)/\1/;P;D' text
Output
Line 1
(Line 3)
Line 4
Line 5
(line 7)
(Line 9)
The N command grabs the next line from the input into the pattern space so that we can perform a pattern matching against two lines. If we discover ####PATTERN###### in the middle, we only keep the second part so that the previous line is deleted. The P command prints the resulted pattern.
Code for sed:
sed -nr '/####PATTERN#######/!{x;1!p;x};$p;h' file
$ sed -nr '/####PATTERN#######/!{x;1!p;x};$p;h' file
Line 1
####PATTERN####### (Line 3)
Line 4
Line 5
####PATTERN####### (line 7)
####PATTERN####### (Line 9)
Code for GNU awk:
awk '{if ($0 ~ /PATTERN/ && NR>1) {delete l[(NR-1)]}; l[NR]=$0}END {for (a in l) print l[a]}' file
$ awk '{if ($0 ~ /PATTERN/ && NR>1) {delete l[(NR-1)]}; l[NR]=$0}END {for (a in l) print l[a]}' file
Line 1
####PATTERN####### (Line 3)
Line 4
Line 5
####PATTERN####### (line 7)
####PATTERN####### (Line 9)
Here is one way with awk:
awk '/PATTERN/{for(;i<NR-2;)print lines[++i];i=NR;delete lines;print $0}{lines[NR]=$0}' file
Output:
$ cat file
Line 1
Line 2
####PATTERN####### (Line 3)
Line 4
Line 5
Line 6
####PATTERN####### (line 7)
Line 8
####PATTERN####### (Line 9)
$ awk '/PATTERN/{for(;i<NR-2;)print lines[++i];i=NR;delete lines;print $0}{lines[NR]=$0}' file
Line 1
####PATTERN####### (Line 3)
Line 4
Line 5
####PATTERN####### (line 7)
####PATTERN####### (Line 9)