LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: Disabled
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
...
...

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

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

Last edited by lleb; 04-17-2013 at 12:26 PM.
 
Old 04-18-2013, 03:36 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
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, 04:29 PM   #4
cortman
Member
 
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.
 
  


Reply


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 04: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 06:35 AM
how to replace line of file with another line using awk in shell script amit_pansuria Programming 3 03-29-2009 09:43 AM
The answer is half a line, but... GRboss Fedora 4 08-07-2006 01:56 PM


All times are GMT -5. The time now is 12:40 PM.

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