The following code executes perfectly:
do for [i=1:$M_Orbs]{
set table 'L_z_'.i.'.dat'
plot [0:250] "L_z_expectation.dat" u 1:2+2*((i-1)*$M_Orbs+i) smooth cspline w l
unset table
set table 'Nocc_'.i.'.dat'
plot [0:250] "NO_PR.out" u 1:2+$M_Orbs-i smooth cspline t 'M='.i w l
unset table
}
But I have trouble when I try and combine these files in a loop using the paste command:
plot for [i=1:$M_Orbs] '< paste 'L_z_'.i.'.dat' 'Nocc_'.i.'.dat'' u 1:(\$2*\$5)
This line brings up the error,
plot for [i=1:2] '< paste 'L_z_'.i.'.dat' 'Nocc_'.i.'.dat'' u 1:($2*$5)
^
line 0: x range is invalid
I'm pretty sure the error occurs because gnuplot tries to execute the paste command before assigning i to it's value in the for loop. Is there another way of escaping the i, or atleast implimenting the same idea in another way?
You have wrong quotes.
Inside single quotes ' you can use either double quotes " without escaping them, or double single quotes '' (which is the way single quotes are escaped).
But the filenames given to paste mustn't be quoted, so your plot command becomes:
plot for [i=1:$M_Orbs] '< paste L_z_'.i.'.dat Nocc_'.i.'.dat' u 1:(column(2)*column(5))
column(2) is the long version of $2, but must not be escaped.
You could also use sprintf to format your file names:
plot for [i=1:$M_Orbs] '< paste '.sprintf('L_z_%d.dat Nocc_%d.dat', i, i) u 1:(\$2*\$5)
I prefer the latter variant, because it allows you e.g. to pad the numbers with zeros: sprintf('L_z_%03d.dat', ).
Related
I have a csv source file with comma (,) delimiter and values are enclosed with double quotes (") and using Text file Input to read the data in PDI 8.3. I am using , in Separator and " in Enclosure options in Content tab.
However, there is a field that contains quotes within the double quotes in the values itself, see the example below:
"abc","cde",
"abc" - 1st col
"cde" - 2nd col
"ef"A"gh" - 3rd col
"ijk" - 4th col and so on..
And issue in the 3rd col, in output it's reading "ef" as 3rd col and remaining values is passing to the next subsequent col. Hope I am able to clarify the issue here, only Expecting to escape the " within the values.
I have tried " in the Escape option but it's not working. Can someone please suggest how to handle this.
Thanks!
You can just leave the Enclosure attribute empty. That way the string will only be divided into columns by the Delimiter.
See CSV File Input Doc and Text File Input Doc
I have a very large set of data that represents cartesian coordinates in the form x0,y0,z0,x1,y1,z1...xn,yn,zn. I need to create a new line at the end of each xyz coordinate. I have been trying to record a macro that moves a certain number of spaces from the beginning of each line, then creates a new line. This, of course, will not work since the number of digits in each xyz coordinate differs.
How can I create a macro to do this in Microsoft Word?
Try this:
Public Sub test()
Dim s As String
Dim v As Variant
Dim t As String
Dim I As Long
s = "x0,y0,z0,x1,y1,z1,xn,yn,zn"
v = Split(s, ",")
t = ""
For I = LBound(v) To UBound(v)
t = t + v(I)
If I Mod 3 = 2 Then
t = t + vbCr
Else
t = t + ","
End If
Next I
t = Left(t, Len(t) - 1)
Debug.Print t
End Sub
The Split function splits a string along the delimiter you specify (comma in your case), returning the results in a 0-based array. Then in the For loop we stitch the pieces back together, using a carriage return (vbCR) every third element and a comma otherwise.
The final (optional) step is to remove the trailing carriage return.
Hope that helps
The question placed before us was most clearly asked
“Please produce a macro sufficient to the task
I have Cartesian coordinates, a single line of these
Array them in many lines, triplets if you please!”
Instinctively we start to code, a solution for this quest
Often without asking, “Is this way truly best?”
But then another scheme arises from the mind
That most venerated duo: Word Replace and Find
Provide the two textboxes each an encantation
Check the Wildcard option and prepare for Amazation!
Forgive me!
In Word open Find/Replace
Click the More button and check the Use wildcards box
For Find what enter ([!,]{1,},[!,]{1,},[!,]{1,}),
For Replace with enter \1^p
Use Find Next, Replace and Replace All as usual
How it works
With wildcards, [!,]{1,} finds one or more chars that are NOT commas. This idiom is repeated 3 times with 2 commas separating the 3 instances. This will match 3 comma-delimited coordinates. The whole expression is then wrapped in parentheses to created an auto-numbered group (in this case Group #1). Creating a group allows us to save text that matches the pattern and use it in the Replace box. Outside of the parentheses is one more comma, which separates one triplet of coordinates from the next.
In the Replace box \1 retrieves auto-numbered group 1, which is our coordinate triplet. Following that is ^p which is a new paragraph in Word.
Hope that helps!
Is there a way on IntelliJ to remove surrounding parenthesis, brackets, quotes, etc? For example, if I have:
"string"
Is there any way to remove the matching quotes and get this?
string
Not directly, but the following replace expression (ctrl+R, tick Regex) might help:
Search for: "(.*)"
replace with: $1
Edit: I found an easier way (plugin code with regex left below for nostalgia)
Webstorm has extend selection and shrink selection
on mac they are bound to alt-upArrow and alt-downArrow
You can use extend selection to select the content and the quotes/braces/parens, then record a macro (i called mine unwrap) and perform the following actions:
shrink selection once
copy
extend selection once
paste
then you can save the macro and add a key binding.
Any time you want to unwrap something, you can just extend the selection until it includes the outer braces, then hit your hotkey and it will replace the selection including the braces with their inner contents.
I made a mini-plugin,
which i install/code using live-plugin.
It relies on this Regex:
[\["'({](.+)['"})\]]
The Regex will also often work in the Search/Replace function in webstorm
(with Regex and In Selection checked), but it fails in mysterious cases:
eg. single quotes that are inside parens - even if the outer parens are not in the selection to be considered
IDEA have an action to go to matching brace.
You can create macro with something like: goto next brace - delete one char - goto prev brace - delete one more char.
And then set kb shortcut to this macro.
Splice Sexp, which is Alt+S on Mac.
I have a curious problem for which I can find nothing on the net and hope someone here can provide some insight:
In a stored procedure, I am traversing a table using a cursor and collating all the values of a single text field (varchar) into a single string variable. Each row I am separating with a Carriage Return / Line Feed (characters 13 and 10).
If I print the variable to the screen, the CR and LF characters are clearly there and in the output in the message window are showing as I would expect by formatting the string into separate lines.
If I check the ASCII values in the string variable at the appropriate positions, the correct ASCII values are showing (13 and 10 respectively)
If I insert the string into a temporary table, I can also see that the CR and LF characters have been retained (by again inspecting the ASCII values in code).
BUT if I 'select' the variable so it appears in a grid and then copy the output and paste into an editor (notepad, word, SQL Query Window etc) the CR and LF have been replaced with spaces.
I don't think this has anything to do with normal Copy/Paste functionality as copying from any other environment retains all the characters. Is there something peculiar to the copy facility when copying a cell in SQL Query Analyser grid output?
While this isn't a show-stopper for me, it does mean I have to jump through some hoops I feel I shouldn't have to - but also, I'm just curious.
Cheers, J
Assuming you are using SQL Server Management Studio, use "Results to Text" (Ctrl+T). That should maintain the line breaks.
If I run this in management studio then copy and paste the resulting cell into notepad it appears correctly:
select 'line1' + char(13) + char(10) + 'line2'
alternatively you could try this:
select 'line1
line2'
in case it's a unicode problem you could try using the unicode crlf equivalent:
select N'line1' + nchar(0x000D) + N'line2'
I'm curious if there is a way to paste text to the end of every line in Sublime 2? And conversely, to the beginning of every line.
test line one
test line two
test line three
test line four
...
Say you have 100 lines of text in the editor, and you want to paste quotation marks to the beginning and end of each line.
Is there an easy way to do this or a plugin that anyone would know of? This would often save me a lot of time on various projects.
Thanks.
Yeah Regex is cool, but there are other alternative.
Select all the lines you want to prefix or suffix
Goto menu Selection -> Split into Lines (Cmd/Ctrl + Shift + L)
This allows you to edit multiple lines at once. Now you can add *Quotes (") or anything * at start and end of each lines.
Here's the workflow I use all the time, using the keyboard only
Ctrl/Cmd + A Select All
Ctrl/Cmd + Shift + L Split into Lines
' Surround every line with quotes
Note that this doesn't work if there are blank lines in the selection.
Select all the lines on which you want to add prefix or suffix. (But if you want to add prefix or suffix to only specific lines, you can use ctrl+Left mouse button to create multiple cursors.)
Push Ctrl+Shift+L.
Push Home key and add prefix.
Push End key and add suffix.
Note, disable wordwrap, otherwise it will not work properly if your lines are longer than sublime's width.
Let's say you have these lines of code:
test line one
test line two
test line three
test line four
Using Search and Replace Ctrl+H with Regex let's find this: ^ and replace it with ", we'll have this:
"test line one
"test line two
"test line three
"test line four
Now let's search this: $ and replace it with ", now we'll have this:
"test line one"
"test line two"
"test line three"
"test line four"
You can use the Search & Replace feature with this regex ^([\w\d\_\.\s\-]*)$ to find text and the replaced text is "$1".
Use column selection. Column selection is one of the unique features of Sublime2; it is used to give you multiple matched cursors (tutorial here). To get multiple cursors, do one of the following:
Mouse:
Hold down the shift (Windows/Linux) or option key (Mac) while selecting a region with the mouse.
Clicking middle mouse button (or scroll) will select as a column also.
Keyboard:
Select the desired region.
Type control+shift+L (Windows/Linux) or command+shift+L (Mac)
You now have multiple lines selected, so you could type a quotation mark at the beginning and end of each line. It would be better to take advantage of Sublime's capabilities, and just type ". When you do this, Sublime automatically quotes the selected text.
Type esc to exit multiple cursor mode.
Select all lines you want to add a suffix or prefix.(command+ A to select all the lines)
Press command+shift+L. This will put one cursor at the end of every line and all the selected lines would still be selected.
For adding suffix press command+right and for adding prefix command+left. This will deselect all the earlier selected text and there will only be cursors at the end or start of every line.
Add required text