Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
"Create a shell script that changes the selected word to another word in all files from selected archive. The script has 3 parameters: archive, old-word, new-word."
2. Relevant commands, code, scripts, algorithms:
This is a begginer's level exercise, we were instructed to use simple solutions such as loops
3. The attempts at a solution (include all code and scripts):This was my attempt:
My TA told me this but I believe I could not understand how to do that: "you should make an error-proof script that does not overwrite any file. If I
would have a file called 'temp', you will overwrite it. The same will happen if
two people will run your script simultaneously.
It should work with commandline parameters also. In case of any error it
should report the error to standard error output.
Perform testing on filenames (inside the archive, archive name, directory
names) containing spaces."
4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
CVUT "České vysoké učení technické v Praze", Czech Republic, Praha, Miroslav Bursa, Operating systems and networks, we don't have a page for the class that i know of. [/b]
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
You shouldn't do mv like that, creating a new file instead of overwriting the old runs the risk of changing the permissions and ownership of the file. You should overwrite the existing file with cat afterwards instead.
I think what he wants is this:
'mktemp' generates a random, unique filename inside /tmp/ for you to use. You will never get the same filename twice, making it safe to run several of your script at the same time.
If you don't have mktemp, do TMP=/tmp/$$ which is almost as good a unique name, tied to your process ID ($$), but less secure because someone outside your process will be able to guess which file you are using.
Under Linux, you can do this all in one step with
...but like your first solution, this runs the risk of changing the ownerships of files. Sometimes people have run sed -i as root and later found that all their files are unwritable -- because they're all owned by root now!
Hi everyone, first time visitor to these forums here.
Keeping a long story short I've been attempting to learn how to code in bash. I have VERY little previous experience with coding languages besides simply copying and pasting batch scripts for Windows. So, with that in mind I've followed a... (4 Replies)
So guys basically I was really sick and couldn't attend the labs and lectures and I went to my lecture hoping he would say ok I will help you from the start but he just said google it. So If it's possible to make the assignment and explain more in detail why is that would be really helpfull.
I can... (1 Reply)
1. The problem statement, all variables and given/known data:
Arguments:
http://farm9.staticflickr.com/8070/8212131370_8b6e8c10c5_c.jpg
I am given these three arguments. $1, $2, $3
The first argument is the path to a directory.
So, how would I go into the directory and compare files?
I... (5 Replies)
Hi Guys-
I'm trying to write a script which takes date as input (mm.yy.dd) and search in the current file. If pattern doesn't exist it will then look in a backup directory and so on.
being a newb i'm unable to loop over to the backup directory. hoping for some ideas, i've highlighted the... (1 Reply)
Hello,
I'm new to Sheel script and I need your help for a script I need to develop (for me).
Indead, I have a software which log all entry from internet and save it in text file.
But, the log is practically unreadable because every 256 characters jump to a new line (even if the message is... (5 Replies)
I have been following a tutorial on bash which has proven to be very helpful. However, i am stuck with a command not found issue when asking for a y/n response from the user. Below is the part of code I believe is giving me grief... I have been trying to work through this for 3 hours now.... Please... (5 Replies)
. ./testFile.sh
url=http://ichart.finance.yahoo.com/table.csv?s= suf=&d=5&e=9&f=2009&g=d&a=1&b=4&c=1999&ignore=.csv
wget $url$s1$suf;
sleep 10;
cat header.txt > $s1.txt;
chmod 777 $s1.txt;
sed '1d' table.csv?s\=$s1 >> $s1.txt;
rm -Rf table*
Very new at shell scripting as you can see... (3 Replies)
I have a folder with lots of file. e.g. a.txt, b.txt, c.txt.... I want to put these files from the source directory and place them in a destination directory in a specific order, such as /destination/a/a.txt, /destination/b/b.txt, /destination/c/c.txt, ......
Please help. Thx :confused: (3 Replies)
Dear All,
I'm trying to write a shell script that continously checks a certain folder. When a file is placed in the directory securely copies the file to another server.
I've got the secure copying working, but I don't know how to contiously check a directory for a new file and then use that... (3 Replies)