I am trying to write a script for Linux on tcsh. I have not written a script since maybe 98 on Unix and that was very basic stuff.
I am trying to take a string and find sub strings in it. For example in a very long string that is a devices status I'd like to find a sub sting "the status: " and if said sub string is found read the next word(string) following that sub string.
Basically I have a variable called INFO that is populated after sending out a command and I want to search it. I can of course loop through the whole thing but I know there are shorter ways of doing so, I just can't remember how anymore.
Plus if anyone knows of a decent source for script writing info that would be of use to me.
Hope this makes sense. PS If it were my choice I'd write this in straight up code and be done yesterday, but not my decision.
Thanks.
Here's a good tutorial source, it has several sections: http://www.dreamsyssoft.com/unix-shell-scripting/tutorial.php
Related
Is there anybody who can get me started on this? I have very very few knowledge about python and at my college python is not even taught. However, in my Linux class my instructor insists in writing a program that replaces all periods within a paragraph with a new line. I do not want you to make my homework, but I feel a bit lost with this assignment. My pre knowledge is in c and java, both introduction levels. Can you please give me a hint on even how to start on this? Thank you very much.
Python has a string method called replace. You can use it like this.
string = """this is a test. This is another. And so on."""
newstring = string.replace(".", "\n")
print(newstring)
You can try yourself here.
so I would like to ask you for help.
I was scooping and sweeping the internet so long for that and I did not find how to do it. What I just produced is totally wrong and my professor did bad time with formulating the task. it is entry level task on university I have already finished the hardest ones, but this one I just dont get what he wants
Translation is made by me so it might be little bit off, but bear with me, please.
"Create file "linewriter.py". This file will have function writeTextToFile, that will accept one parameter and on end is also one parameter. Function will take the parameter on input and chain it with variable STATIC_TEXT (stated bellow). Queue of chaining will be as follows: 1st static text and then argument of function. This way chained input will write to file of any given name and a the name of this file will be returned as input parameter of function.
STATIC_TEXT: “This is my static text which must be added to file. It is very long text and I do not know what they want to do with this terrible text. ”
...
What? I really don't get what he want's from me. Can you help? Thank you all :)
STATICKY_TEXT = "This is my static text which must be added to file. It is very long text and I do not know what they want to do with this terrible text.\nNew Line! "
saveFile = open ("exampleFile.txt","w")
saveFile.write(STATICKY_TEXT)
saveFile.close()
solved it :) but I COULD not figure it out for days haha ... silly me
Lets say that there is a function in my Delphi app:
MsgBox
and there is a string which has MsgBox in it.
I know what most of you are going to say is that its possible, but I think it is possible because I opened the compiled exe(compiled using delphi XE2) using a Resource Editor, and that resource editor was built for Delphi. In that, I could see most of the code I wrote, as I wrote it. So since the variables names, function names etc aren't changed during compile, there should a way to execute the functions from a string, but how? Any help will be appreciated.
EDIT:
What I want to do is to create a simple interpreter/scripting engine. And this is how its supposed to work:
There are two files, scr.txt and arg.txt
scr.txt contains:
msg_show
0
arg.txt contains:
"Message"
And now let me explain what that 0 is:
First, scr.txt's first line is function name
second line tells that at which line its arguments are in the arg.txt, i.e 0 tells that "Message" is the argument for msg_show.
I hope my question is now clear.
I want to make a simple scripting engine.
In order to execute arbitrary code stored as text, you need a compiler or an interpreter. Either you need to write one yourself, or embed one that already exists. Realistically, the latter option is your best option. There are a number available but in my view it's hard to look past dwscript.
I think I've already solved my problem! The answer is in this question's first answer.
EDIT:
But with that, as for a workaround of the problem mentioned in first comment, I have a very easy solution.
You don't need to pass all the arguments/parameters to it. Just take my example:
You have two files, as mentioned in the question. Now you need to execute the files. It is as simple as that:
read the first line of scr.txt
check if it's a function. If not, skip the line
If yes, read the next line which tells the index where it's arguments are in arg.txt
pass on the index(an integer) to the "Call" function.
Now to the function which has to be executed, it should know how many arguments it needs. i.e 2
Lets say that the function is "Sum(a,b : integer)".It needs 2 arguments
Now let the function read the two arguments from arg.txt.
And its done!
I hope it will help you all.
And I can get some rep :)
i have a file with below data
this is a text file with html format $testarray['G']
i use this script but it is not work properly.
<?php $testarray=array();
$testarray['G']=100;
$result222 =file_get_contents(realpath('file.php'));
printf($result222);?>
i want this script, print out below line
this is a text file with html format 100
i do't want to use include or require function because user can insert php code in this file and i do't want user can use php codes in this file
can anybody help me?
many thanks
If you know the string you expect to perform a substitution on, you can always do it manually with str_replace(). However, it looks like you want to be able to substitute arbitrary variables into the string, which I implore you to not do. You are giving this PHP script way too much power as is. I can think of a few exploits off the top of my head, such as injecting superglobals among simply brute forcing variable names.
Edit: I realize now that I also didn't give you the straightforward answer which does as you request: the eval() function. You should be able to craft a string that assigns the contents of the file to a variable, which should perform variable substitutions by the PHP parser. Please don't use it, but if you do be very careful.
i used below script
$result222 =file_get_contents(realpath('file.php'));
$result222=str_replace(array("<?","?>")," ",$result222);
print eval("return<<<ENDEVAL\n$result222\nENDEVAL;\n");
I have text file in VB6 Application resources, and I am trying to read the text in it.
How to do that? I have been searching for hours without a proper solution. Somebody please help me.
My code is:
Private Sub Command1_Click()
Dim URL As String
URL = LoadResString(101)
MsgBox URL
End Sub
This maybe explains it more: http://i.imgur.com/wGnWCBb.jpg
Is this even possible? Somebody please spoonfeed me, I would appreciate that a lot.
I am trying to read the string from resource to a variable(string) and then prompt it with messagebox.
Some simple solution would be great. Also, if this is possible with FindResource API, please tell me how or point me to the right direction.
I had to do something like this many years ago.
I used s = StrConv(LoadResData(resId, resType), vbUnicode). The resource was an ANSI (non-unicode) file.
resType was a custom type I just made up when I saved the resource.
I had an issue with a double null that got appended at the end of the text, and which had to be removed. I can't remember the exact reason why that happens, but I presume it has to do with the resource being stored as a double-null-terminated list of C-strings.
If I had to guess, you'll have better luck with LoadResData(). Make sure to use both parameters (the id and type ones).