A shell Script to exchange the content of two files
Hallo all
Could someone help me? I am absolute beginner in shell script Programming. I was asked to write a shell script that can automatically exchange the content of two files, independent of present working directory. Meanwhile , the script should print the text „THE CONTENT OF FILE:“ before the actual content of the files on the screen. Only 4 commands must be used in the assignment: 2 copy, 1 mv and 1rm commands. Currently the files which content should be exchanged are located in: FILE1: ~/subdir1/file1 FILE2: ~/subdir1subdir2/file2 Thanks in advance ranks |
You could start by reading at least parts of these:
http://tldp.org/LDP/Bash-Beginners-G...ers-Guide.html http://www.freeos.com/guides/lsst/ Other than that, post what you have tried to start with, and someone will help when you get stuck, but you'll have to at least try. |
Oh, come on, it's far too simple for us to give you the answer, we shouldn't anyway because it will not help you learn anything. Think about what you would do in any language, how would you spend those cp, mv, and rm commands ? Take a look at the man pages 'man cp', 'man rm', 'man mv'.
|
Do it in human language, once you have the steps described in a readable manner, take your class notes and read them.
We are not doing the homework for you. We can help you with concrete problems if you get stuck, though. |
A shell Script to exchange the content of two files
Thanks for your effort. It is not my way of solving assignment problems. Unfortunately I only have two and the last pages in my book that handle shell script programming, then I will go on another subject. That means know proper orientation point for task of this kind. I will see what I can do with the available information already on this forum.
|
Try to think in very simple way...suppose you have 2 bags of books :)what you will do to exchange them....think this first..read man page of cp, rm and mv...and try with a simple script...if it doesnot work, post that...we will help you (it will be hardly 2-3 lines)...and if u succeed u will gain lot of confidence...
happy coding.. cheers- kd |
I would say start thinking post-it notes. You have two notes on a table, one on the left says "hello", one on the right says "bye".
At the end a note can cover another beneath it. 2 copy, 1 move (and 1 remove) to change the left one to say bye, and right one to say hello. As a side note, type "alias" in your shell. If you see: alias cp='cp -i' alias mv='mv -i' alias rm='rm -i' You need to unalias or figure out how to force the commands in the script. "-i" asks before overwriting. |
You are absolutely right that I should first make effort myself. I don't want this to be a barrier in my programming carrier. I must try my best. If no success I will post the script here.
regards |
Sure....it is great to see ur spirits.
Good luck !!:) |
write the shell script that can automatically exchange the content of two files
Hallo all,
I still can't figure out how to correctly write the shell script that can automatically exchange the content of two files, independent of present working directory. This is what I have so far done. THE SHELL SCRIPT: Code:
clear Now the script can automatically tranfer the content of the file „da2“ to file „da1“, but can't tranfer the content of file „da1“ to „da2“ . The script should set back the content of the files when run the second time but it is not the case. Any idea of what to do to make it work properly? Thanks in advance ranks |
It's a bit tricky because normally you would use 1 mv instead of the cp + rm combo. So here's my hint:
The order should be cp, mv, cp, rm. Example: Code:
bash-3.1$ find |
Thanks H_TeXMeX_H, please what do you mean by file-temp and new? Are they folders?
regards ranks |
Quote:
Then those 2 commands: Code:
bash-3.1$ cp new/file-temp new/file2 Code:
mv new/file-temp new/file2 |
All times are GMT -5. The time now is 08:54 PM. |