LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   replace half line in file by another half line of file (https://www.linuxquestions.org/questions/linux-newbie-8/replace-half-line-in-file-by-another-half-line-of-file-4175458503/)

komalp 04-17-2013 12:08 PM

replace half line in file by another half line of file
 
hii...

in my prog i want to replace half of the line by another file's half line.
in shell script.
example:
file1
Code:

....
........
this is bucket of mangoes.
...........
.......


file2
Code:

.....
that is ice cream with cold drinks
.....
...

o/p file
Code:

....
this is ice cream with cold drinks
...
...


lleb 04-17-2013 12:24 PM

you can use the standard find/replace in any GUI or text editor. I personally prefer vi (or vim in some cases) its a rather simple syntax:

Quote:

Give a skeptic and inch... and he'll take a mile.

and typed


:s/take a mile/measure it/

I would be left with

Give a skeptic and inch... and he'll measure it.
that is what you would do on the line you want to edit, now if you want to make this a global add a g at the end of the command:

Code:

:s/take a mile/measure it/g

David the H. 04-18-2013 03:36 PM

This sounds a lot like a homework question, and per the LQ rules we won't give you specific answers. But we can help guide you to a solution.

So to start with, what have you attempted so far, and where exactly are you having trouble?

cortman 04-18-2013 04:29 PM

^This, and please define "half of a line". In your example, "this" is not half of the line.


All times are GMT -5. The time now is 02:23 AM.