LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to update a file in bash (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-update-a-file-in-bash-858801/)

520Soul 01-26-2011 10:59 AM

how to update a file in bash
 
hi guys. I have been looking for some example of how to update a file that is already exist in bash. so far i haven found any. I'm using parameter as my first start for the existent, copy file to a different directory. can you guys help me please, show me some example of anyway to update a file.

thanks ahead guys..

goossen 01-26-2011 11:02 AM

I'm not sure if I understood correctly your question. But if you wanna edit a file check the command sed.

xeleema 01-26-2011 01:18 PM

@520Soul
Greetingz!

This kindof depends on the contents of the file in question, and exactly what you want to change. For example, as goossen pointed out, sed can really help out.
Sed One-Liners Explained, Part I
Sed One-Liners Explained, Part II
Sed One-Liners Explained, Part III
There's also awk, cut, grep, and a slew of other commands. Again it all boils down to what you're trying to do to the file in question.
(Some sample output would be nice, along with what you're trying to accomplish)

520Soul 01-26-2011 03:07 PM

sorry for bad description.
 
Quote:

Originally Posted by goossen (Post 4238388)
I'm not sure if I understood correctly your question. But if you wanna edit a file check the command sed.




for instant, a file1 have data A,b,c. now file1 is re-written. and you want to update it. i think update and replace is the same right? i'm not sure if the word update is the correct word. it is like the file is old and you want to replace the old file with new one. does it has to have the same file name? i don't think it matter right?

devUnix 01-26-2011 03:35 PM

Quote:

Originally Posted by 520Soul (Post 4238662)
for instant, a file1 have data A,b,c. now file1 is re-written. and you want to update it. i think update and replace is the same right? i'm not sure if the word update is the correct word. it is like the file is old and you want to replace the old file with new one. does it has to have the same file name? i don't think it matter right?


Try this, in the same sequence, to understand some file operations:

Code:

#cal > myCal <ENTER>
#cat myCal <ENTER>
#date > myCal <ENTER>
#cal >> myCal <ENTER>


schneidz 01-26-2011 04:48 PM

the obvious would be cp, mv, rm, ...


All times are GMT -5. The time now is 05:53 PM.