Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-17-2013, 01:08 PM   #1
LQ Newbie
Registered: Apr 2013
Posts: 10

Rep: Reputation: Disabled
replace half line in file by another half line of file


in my prog i want to replace half of the line by another file's half line.
in shell script.
this is bucket of mangoes.

that is ice cream with cold drinks
o/p file
this is ice cream with cold drinks

Last edited by komalp; 04-17-2013 at 01:31 PM.
Old 04-17-2013, 01:24 PM   #2
Senior Member
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora
Posts: 2,758

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
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:

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:

:s/take a mile/measure it/g

Last edited by lleb; 04-17-2013 at 01:26 PM.
Old 04-18-2013, 04:36 PM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,845

Rep: Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006
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?
Old 04-18-2013, 05:29 PM   #4
Registered: Jan 2012
Location: ZZ9 Plural Z Alpha
Distribution: Crunchbang 11, LFS 7.3, DSL 4.1.10, Lubuntu 12.10, Debian 7
Posts: 219

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
search folders, find a line in a file, and replace it with a new line ithirdeye Programming 2 04-07-2012 05:27 PM
Perl: Match part of a line and replace with another line from the same file briana.paige Linux - Newbie 8 06-27-2009 07:35 AM
how to replace line of file with another line using awk in shell script amit_pansuria Programming 3 03-29-2009 10:43 AM
The answer is half a line, but... GRboss Fedora 4 08-07-2006 02:56 PM > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration