How do I ignore comments in a text file with LabVIEW? - comments

I've created a script file reader, nothing more than a glorified text reader that changes loop cases in my program, but I need it to be able to ignore comments on a line, execute that command, and go to the next line and process the new command after it finds the comment denoted with a semicolon. For the life of me, I can't figure out how to do this.
Currently, the commands are read in like this:
DO THIS FUNCTION
DO THAT FUNCTION
I'd like to comment it with a semicolon like this:
DO THIS FUNCTION ;this is a comment to be ignored
Below is my text file read code, should be able to drag and drop it in to test. The command indicator just echoes the command being read. I've removed the rest of my program, sorry, can't send that part.
Can someone shed some light?

Is a semicolon used anywhere else in your file? Or is it just used to indicate a comment?
If it is only used to indicate a comment then as you read each line in, call the Split String primitive and split at the ";". Just use the top output regardless of whether or not the line contains a semicolon:

You can use the "Match Regular Expression Function" to split up the string, as #Moray already suggested.
Sadly I can't give you an example vi right now.
The main idea is:
find the "Match Regular Expression Function"
give it a ; as char to search for
there are three outputs of the function (before match, match, after match)
use the 'before match' instead of the whole line and give it to the rest of your program
This only works if your commands don't contain any ; except for the comments.
Note: I not quite sure what happens if you give the function a string that doesn't contain ; but you can figure that out by yourself by using the detailed help to this function :)

Related

How to delete quotation mark in text file printed

I'm honestly a novice on scilab.
I'm using print function to create .txt file with my character matrix in it.
But , when I open txt file, double quote appeared. I just want words without "".
This is how I'm using print
Compterendu(1,1)= "Medecin demandeur: "
fileresname= fullfile(RES_PATH, "compterendu.txt")
print(fileresname,Compterendu)
And, compterendu.txt was printed out like this.
Would be so grateful for any help!!
Thanks
Why do you use "print" ? After looking into the doc, yes, it is used to produce the same text as when you type the expression or the variable name on the command line. Hence it does print double quotes for strings. If you need something more basic use lower level i/o commands, like mputl.
S.

VIM for Windows: How to edit to the end of line but before EOL character

What I am trying to do:
For example, I have a line in my code that looks like this
something.something()
I would like to add print() around it:
print(something.something())
How I am doing it:
I type in vim: ^c$print()<Esc>P meaning:
put cursor to the beginning of the line,
change entire line,
type in print(),
paste entire line back before print's ).
The Problem:
Unfortunately the c$ part cut the EOL character as well. so the subsequent P operation will just paste the line on top of print(). So the end result will look like this:
something.something()
print()
My Thoughts:
Right now the work around is using v mode to highlight entire line except for the EOL character first, then do the above.
I am looking for something akin to ct$ ci$, but none of them works. my line doesn't always end with (), it could be __dict__ or just plain text, so cf) is handy but I am looking for something more universal. Thanks.
Of course it's doable out of the box.
Assuming your description of what you are doing is exact, the reason what you are doing doesn't work is most likely caused by something in your config because c$ (or its better alternative C) should never yank the EOL.
Here is a demonstration using your method as described in your question:
^c$print()<Esc>P
and the method I would use:
^Cprint(<C-r>")<Esc>
I don't think you want to be going into edit mode at all. Just do:
:s/something.something()/print(&)/g
Note that you can do this pretty easily interactively (eg, you don't have to type 'something.something()') by yanking something.something into the unnamed register (eg, put your cursor on the text and hit 'yiw', but what gets yanked exactly will depend on the current setting of iskeyword), and typing :s/<ctrl>r"/...
Or, as Christian Gibbons points out in the comments, if you want to replace the entire line you can simply do:
:s/.*/print(&)
Try ^cg_print()<Esc>P.
The g_ movement means "to the last non-blank character of the line", and since in Windows it appears the carriage return is part of the line if you yank/delete, using _g instead of $ on Windows may be advisable.
If you find yourself almost never needing $, you can swap the two commands in your .vimrc:
onoremap g_ $
onoremap $ g_

Use bash to extract data between two regular expressions while keeping the formatting

but I have a question about a small piece of code using the awk command. I have not found an answer/solution anywhere.
I am trying to parse an output file and extract all data between the 1st expression (including) ATOMIC and 2nd expression (excluding) Bond. This data is to be sent to a new file $1_geom. So far I have the following:
`awk '/ATOMIC/{flag=1;next}/Bond lengths in Bohr/{flag=0}flag' $1` >> $1_geom
This script will extract the correct data for me, but there are 2 problems:
The line ATOMICis not extracted with the data
The data is extracted and appended to a single line. I want the data to retain the formatting from the parsed file (5 columns, variable amount of lines). Please see attachment to see a visual. Visual Example Attachment. Is there a different way to append data (other than >>) so that I can keep formatting?
Any help is appreciated, thank you.
The next is causing the first match to be skipped; take it out if you don't want that.
The backticks by themselves are a shell syntax error (unless your Awk script happens to produce valid shell commands). I'm guessing you have a useless echo or something like that in your actual script which disarms the error, but instead produces the symptoms you describe.
This was part of a code in a csh script and I did have an "echo" in front of this line. Removing the "echo" makes it work perfectly and addresses the 2 questions that I had.

Is there a way to delete all comments in a file using Notepad++?

Notepad++ obviously recognizes all comments as such. Is there a way to simply delete all?
Edit: Stat-R's bookmark method has helped greatly, not only for removing comments but for conditionally removing lines in general.
For a general file, first of all you need to know the comment operator of the language you are writing the file in. For example, in java script the comment operator is //.
For the following code...
In NP++, you need to
Mark the lines that contains '//'. Make sure the bookmark option is enabled.
Then, choose from NP++ menu Search>Bookmark>Remove Bookmarked lines
EDIT:
Another solution after #Chris Mirno 's suggestion is as follows:
Use regular expression. See the image below. It is self explanatory
To understand it better, refer to these
In the Find & Replace Dialog, put the following regex and adjust the search options as depicted.
/\*.*?\*/
Replace with: (empty)
Select Mode: Regular Expression AND .(dot) matches newline
This should remove all your C style comments spanned across lines.
Star-R and Chris Mirno Answer are also Correct and Good.
But For Line Comment:
//.*?(?=\r?$)
Explanation:
// will be the Starting Position
.*? Will be any character
(?=\r?$) will search to the end of the line (as it is required in line comment)
Note:
But Still check each of the line because for example if your code contains soap format like
//www.w3.org/2001/XMLSchema-instance\x2......");
it will capture this line because the starting is // and it goes to end of the line so watch out for this :)
Warning to all using Stat-R's solution:
This method will remove lines of code if formatted like this:
echo "hello"; //This comment will be detected
Following his method, the entire line will be removed.
Therefore make sure to go through and make these comments, their own line before doing this method.
I have had some luck running a macro for the above. Basically:
search for // (F3)
select to end of line (shift+end)
delete (delete)
Put // into the search dialog by just searching for it once. Then record the three steps in a macro, then play it back until EOF.
The first time I did it I had a problem, but then it worked, not sure what I did differently.
Anton Largiader's answer was the most reliable one, including complex inline comments.
However, it will leave many empty lines, including ones with empty characters (space, tabs...) so I would just add another step to make it almost perfect:
After running the macro, just do:
Edit > Line Operations > Remove Empty Lines
OR
Edit > Line Operations > Remove Empty Lines (Containing Blank Characters)
1st option is good if you wish to remove only really empty lines
2nd options will remove every empty line even containing space etc. so there will be no more actual spacing left between code blocks. 1st option might be the safest with some manual cleanup afterwards.
As someone suggested in another post, the simplest and most reliable is maybe to export the all text in .RTF format using Menu Plugin-->NppExport-->Export to RTF and then:
-Open the newly created file in Word
-Select any part of any comment
-On the top-right side of Word clic Select--> Select all texts with similar formatting
-Remove the selected comments all at once (del or cut if doesn't work)
To remove Powershell comments if someone find it handy:
Removing Comment in a Powershell using Notepad ++
To find just lines beginning with # (and not with # elsewhere in the line).
Notepad++ SEARCH Menu > Find
‘Mark‘ Tab – fill in as below.
Select ‘Mark All’ (clear all marks if used previously).
Regex ^[#}
enter image description here
SEARCH Menu > bookmark > Remove (or do anything on the list with
them)
Clear all marks to reset
You can select no comments just code by doing the following:
Regex ^[^#}
enter image description here
Enter ctrl+shift+K to remove comment

Inserting characters before whatever is on a line, for many lines

I have been looking at regular expressions to try and do this, but the most I can do is find the start of a line with ^, but not replace it.
I can then find the first characters on a line to replace, but can not do it in such a way with keeping it intact.
Unfortunately I don´t have access to a tool like cut since I am on a windows machine...so is there any way to do what I want with just regexp?
Use notepad++. It offers a way to record an sequence of actions which then can be repeated for all lines in the file.
Did you try replacing the regular expression ^ with the text you want to put at the start of each line? Also you should use the multiline option (also called m in some regex dialects) if you want ^ to match the start of every line in your input rather than just the first.
string s = "test test\ntest2 test2";
s = Regex.Replace(s, "^", "foo", RegexOptions.Multiline);
Console.WriteLine(s);
Result:
footest test
footest2 test2
I used to program on the mainframe and got used to SPF panels. I was thrilled to find a Windows version of the same editor at Command Technology. Makes problems like this drop-dead simple. You can use expressions to exclude or include lines, then apply transforms on just the excluded or included lines and do so inside of column boundaries. You can even take the contents of one set of lines and overlay the contents of another set of lines entirely or within column boundaries which makes it very easy to generate mass assignments of values to variables and similar tasks. I use Notepad++ for most stuff but keep a copy of SPFSE around for special-purpose editing like this. It's not cheap but once you figure out how to use it, it pays for itself in time saved.

Resources