What is the Redis command line (redis-cli) continuation character? - command-line

I am trying to build a redis 'stored procedure' in lua that will update a keyvalue store when one of the map fields changes, and will also extract a value from another key when said value changes. I have built this lua(redis) script and it works.
But I discovered that when I try to enter it into the redis-cli, it complains unless I concatenate all the lines of the script onto one long line. Surely there is a 'continuation character' recognized by the redis-cli (?) but I cannot find it.
Anybody know the continuation character for redis-cli?

One option would be to save the lua script to a file and then use the command line to execute the script in the file as shown here:
http://www.redisgreen.net/blog/2013/03/18/intro-to-lua-for-redis-programmers/
I realize this is not a direct answer to what the continuation character for redis-cli might be (or if it exists).

Related

Perl Command Understanding

I have been working on a product code to resolve an issue but am stuck on a line of code
Can anyone help me understand what exactly does this command do?
perl -MText::CSV -lne 'BEGIN{$p = Text::CSV->new()} print join "|", $p->fields() if $p->parse($_)' /home/daily/${FULL_FILENAME} > /home/output.txt
I think its to copy the file to my home location with some transformations but not sure exactly
This is a slightly broken program that translates a comma-separated values (CSV) file to a pipe-separated values file.
The particular command-line switches are documented in perlrun. This is a "one-liner", so you can read about those to see what's going on there.
The Text::CSV module deals with CSV files, and the program is parsing a line from the file and re-outputting as a pipe-separated file.
But, this program deals with each line as a complete record. That might be fine for you, but at some point you might end up with a literal value that has a newline in it, like a,"b\nc",d. Now reading line-by-line breaks the program since the quotes appear to be unclosed within the first line. Note only that, it blindly concatenates the parsed fields without considering if any of the fields should be quoted. It might be unlikely that a pipe character would be in the data, but the problem isn't it's rarity but the consequences and costliness when it does show up.
The rewrite.pl example script in the related module Text::CSV_XS is a tool that could replace this one-liner. It properly reads the input and knows how to properly translate it.

Problems with Wget64

Attempting to write a Wget to get and save Vanguard pricing data. So far I have 2 statements that both work correctly from the Command Line when I paste the string. When I save the string as a bat file one works and the other gives an unexpected result.
The string that works correctly in both places is:
Wget64 --output-document=C:\Users\Default\downloads\VVA_Daily_Portfolio-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.html "https://personal.vanguard.com/us/funds/annuities/variable"
The string that only works in the Command Line and not as a bat file is:
Wget64 --output-document=C:\Users\Default\downloads\VVA_Fund64_History-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.html "https://personal.vanguard.com/us/funds/tools/pricehistorysearch?radio=1&results=get&FundType=VVAP&FundIntExt=INT&FundId=0064&fundName=0064&fundValue=0064&radiobutton2=1&beginDate=03%2F01%2F2017&endDate=12%2F31%2F2017&year=#res"
Can someone help me write the script so that the expected result is achieved. I suspect that the Vanguard website can tell the difference between a Command Line vs bat file query, or that there is something inherently different between the two methods of execution.
ANy assistance is appreciated. Dan
The cmd command parser behaves differently in command line and batch files. In this case, the main problem is the variable expansion. In command line when a variable does not contain a value (it is undefined), the variable read operation is not removed, but inside batch files the read operation is removed.
That means that something like echo(%thisDoesNotExist% will output (under the assumption the variable does not exist) %thisDoesNotExist% in command line and nothing in batch file.
What relation has this with your problem?
If we split your wget in parts you have
Wget64
--output-document="C:\Us ... y-%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.html"
^........^ ^.........^ ^.........^
"https://pe ... h?radio=1& ... &beginDate=03%2F01%2F2017&endDate=12%2F31%2F2017&year=#res"
^....^ ^....^
You can see where the parser tries to resolve variables, correctly in the output case and incorrectly (from the purpouse of the command point of view) in the URL.
You need to escape (by doubling them) the percent signs that are not part of a variable read operation, ex. ... beginDate=03%%2F01%%2F2017&...

Error when making .bat file to open programs? scripting

****so this is how the bat file program look like and the error code i am geting ( click the drop box link/copy and paste to browser)****
https://www.dropbox.com/sh/6o4h666m0bwav69/AACTAbDe4jhyWdApEQOoAl7Na?dl=0
only program that is coming up is hitmanpro, every others get error
First of all, paste your code and error directly into your questions in the future.
Now then, the issue comes from the incorrect quotes being used. See how the first three pairs are kinda curly and the last ones are straight? Batch can't recognize curly quotes, probably because it's some Unicode thing. Always use straight quotes in batch. It's best if you code in notepad or a similar program; some text editors make the quotes curly automatically and call them "smart quotes."

Perl: How to replace a string in file with a paragraph [duplicate]

This question already has an answer here:
sed find and replace between two tags with multi line
(1 answer)
Closed 8 years ago.
I need to replace a token in a file with a multi-line paragrah, which has several line breakers inside it if the paragraph is represented as a string.
If I use sed the usually for a string to string replacement, the line breakers inside the new string would complain.
So now I want to open the file and seek to that token location, then write the new content into the file from there, but not sure how to achieve that. Can anybody help?
EDIT:
Looks like I probably can put both the file and the content to be inserted as arrays then use splice in perl. Might not be the easiest way though.
perl -i -pe's/token/foo\nbar\nbaz\n/g' file
You can't really insert into a file. Just like inserting into a string, you must first move the remainder of the string out of the way. With files, it's easier just to copy the entire file.
The provided code opens file, deletes file, creates file, then copies (with substitutions) from the open handle to the new handle.
It's my understanding that sed can do this too. It's my understanding that sed also uses -i to enable this feature.
Check out: How do I change, delete, or insert a line in a file, or append to the beginning of a file?
The easiest solutions will be to either use perl's $INPLACE_EDIT, optionally done as a one liner like demonstrated by ikegami, or perhaps to use Tie::File.

zip recursively each file in a dir, where the name of the file has spaces in it

I am quite stuck; I need to compress the content of a folder, where I have multiple files (extension .dat). I went for shell scripting.
So far I told myself that is not that hard: I just need to recursively read the content of the dir, get the name of the file and zip it, using the name of the file itself.
This is what I wrote:
for i in *.dat; do zip $i".zip" $i; done
Now when I try it I get a weird behavior: each file is called like "12/23/2012 data102 test1.dat"; and when I run this sequence of commands; I see that zip instead of recognizing the whole file name, see each part of the string as single entity, causing the whole operation to fail.
I told myself that I was doing something wrong, and that the i variable was wrong; so I have replaced echo, instead than the zip command (to see which one was the output of the i variable); and the $i output is the full name of the file, not part of it.
I am totally clueless at this point about what is going on...if the variable i is read by zip it reads each single piece of the string, instead of the whole thing, while if I use echo to see the content of that variable it gets the correct output.
Do I have to pass the value of the filename to zip in a different way? Since it is the content of a variable passed as parameter I was assuming that it won't matter if the string is one or has spaces in it, and I can't find in the man page the answer (if there is any in there).
Anyone knows why do I get this behavior and how to fix it? Thanks!
You need to quote anything with spaces in it.
zip "$i.zip" "$i"
Generally speaking, any variable interpolation should have double quotes unless you specifically require the shell to split it into multiple tokens. The internal field separator $IFS defaults to space and tab, but you can change it to make the shell do word splitting on arbitrary separators. See any decent beginners' shell tutorial for a detailed account of the shell's quoting mechanisms.