I am completely new to Shell scripting and I have almost no idea what I'm doing here. I'm not a stranger at all to programming, but the way SHELL is done drives me to insanity. Here's my current issue:
1. We are to create a BASH script called rafactor.sh This program takes in two (or three) arguments. A Java class name, (without the .java extension) and a "new" Java class name (again with no extension), optionally a directory may be given as an argument.
This script must search each source file for the first argument and replace it with the second, THIS HOWEVER DOES NOT INCLUDE PATTERNS (i.e. arg1:aaa, arg2: AAA will not change: aaaInstance, but will change: aaa).
The directories must be searched recursively (but does not have to be done using "recursive programming")
Additional requirements:
Check that at least two arguments are given
Check that the second argument is "valid" (no numbers, or spaces, just alphanumeric characters and underscores)
The source file name must also be changed if it has the same name as the first argument (i.e. aaa.class changes to: AAA.class)
Instances of the class name within the program must be changed accordingly (if the class name was changed)
The script must recurse through the directory
sed and find must be used.
2. Relevant commands, code, scripts, algorithms:
sed and find must be used.
3. The attempts at a solution (include all code and scripts):
The above code is obviously no where near complete, it also doesn't have all the attempts I've made to make heads or tails of how to tackle the problem in my terminal.
I created two dummy files and placed them in a folder on my desktop called "Test" and attempted to change every instance of "blah" to "moo" in both files, and I can't even seem to do that.
I cannot get my program to recognize temp and backup folders which are also on my desktop.
The only success I've managed to achieve thus far is a simple sed substitution in a single dummy file from "blah" to "moo" however I cannot restrict it to single instances (as opposed to patterns within the file).
Perhaps I don't have enough knowledge to tackle this problem, we've only been scripting for a couple weeks, and I can't even properly write a factorial program yet...
Things as simple as if statements throw errors if I so much as look at them and I've yet to successfully compile a BASH script on my own.
4. University of Windsor, Windsor(ON),Canada, Prof. Rahaman, (I do not have 5 posts and therefore am unable to post the course URL. I will edit this when I have enough posts) course number 03-62-256
I've tried breaking this down into smaller chunks, but I can't even seem to do that. I've been scouring my notes for the last few hours, trying to get SOMETHING to compile right, but I can't even get that far.
Addition to help with this problem, if there's any special hints anyone could give me concerning compiling in general, I'd greatly appreciate it.
You've got an 'if' with no 'fi' and no 'then'. The ; on the end seems to have no reason to be there -- ; is treated like a linebreak, so you can do command1 ; command2 but the line ends right there anyway...
The usual syntax goes
where STATEMENT can be:
I'd like to see an example of what an input source file would look like, and what the file ought to look like after substitution.
Thanks Corona, I didn't actually realize that a ";" meant a line break, I thought it was part of the if statement process.
Here's some sample input/output:
output:
I'm going to point out again how the pattern is not changed, but rather explicit instances of the original input is changed.
Also, I know that the example I gave (which is from the assignment) just capitalizes, and that can be done using the "tr" command, but that's not at all what the professor wants.
I also apologize for my lack of an attempt. I'm just that lost. If this were any other programing language I wouldn't even be posting
Thanks Corona, I didn't actually realize that a ";" meant a line break, I thought it was part of the if statement process.
You'll sometimes see if statements shortened like if this ; then that ; fi which is probably the source of the confusion.
Quote:
Here's some sample input/output:
output:
I'm going to point out again how the pattern is not changed, but rather explicit instances of the original input is changed.
Also, I know that the example I gave (which is from the assignment) just capitalizes, and that can be done using the "tr" command, but that's not at all what the professor wants.
I also apologize for my lack of an attempt. I'm just that lost. If this were any other programing language I wouldn't even be posting
Hmm.
You can tell it's at least a whole word and not part of another word when the first char is either whitespace, brackets, semicolon, or the beginning of the line; and the last is either whitespace, brackets, semicolon, or the end of the line... This won't protect you from having the name inside strings though:
Woah! You lost me there, with your hip, young lingo son! (sorry, bad joke)
I was considering trying to modify the input to include white space, that way it'd be more distinguishable from other strings with the pattern inside it, but even if I wanted to, I can't get anything to compile yet.
Also... could you document your code for me? All I understand is "echo" and I see a few "pipes"
Ok. I get it now. The extra "\" makes it a bit overwhelming, but I understand what you've done. That's actually pretty clever and I probably wouldn't have considered it as a solution in any other programing language.
I think it's helped me think of a way to check for validation also. I'll post an updated code and any more problems once I've made the adjustments and have had some thinkin' food.
Hi gurus/lead,
I have one doubt in crontab. I have shell script source code in one server. where I don't have priviliges acess R/W the shell script in that server.
how can I setup the crontab to pick the code from the other unix server ?
whether is there any possibility.
in my... (1 Reply)
If you are interested in a set of utilities designed for reporting solutions within the shell, check out CRUSH on Google code.
crush-tools - Project Hosting on Google Code (0 Replies)
I'd like to be able to do something like 'select column_a column_c column_b from file.csv'. Scripting it probably wouldn't be too extraordinarily difficult but I'd rather not reinvent the wheel if someone's built a better one already. (3 Replies)
hi experts,
i have a file
sample:
=======
000123 5 7 0008
00345 5 9 0004
how can i get an output as
123 5 7 8
345 5 9 4
thanks in an advance
subhendu (5 Replies)
Let's get some feedback about the top ten ute's you guys use in writing your scripts - I mean yeah it depends on the job and what you're trying to accomplish, but there ARE those commands (sed, grep, awk, cut, etc.) that most will use time and again...
...so, what do you use? (3 Replies)
Hi all ---
I have the need to manage multiple versions of a set of utility scripts -- both shell and SQL and other .dat files. I am wondering if anyone out there knows of a good way to "PATH" to SQL and text files in a way similar to how PATH facilitates finding executables in a pre-specified... (2 Replies)