Find and replace the line in text file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Find and replace the line in text file
# 1  
Old 06-20-2012
Find and replace the line in text file

I have two files
a.txt
b.txt
I want to find a line in a.txt and replace by another line from b.txt

Code:
 a.txt
asfsdfsfsfdfsf
asfwererfgdgf
wrerwetretfdg

Code:
 b.txt
werdfgdfgf
werergfdgd
sfdfgfgfgfgg

i want to replace the 1st line of a.txt by 1st line of b.txt

i want out put as
Code:
a.txt
werdfgdfgf
asfwererfgdgf
wrerwetretfdg

i want the script for it.pls help
# 2  
Old 06-20-2012
Code:
( head -n 1 a.txt
tail -n +2 b.txt ) > c.txt

# 3  
Old 06-21-2012
Hi guys any codes for the following question...in order to replace the line in file.
# 4  
Old 06-21-2012
Quote:
Originally Posted by rammm
Hi guys any codes for the following question...in order to replace the line in file.
Quote:
Originally Posted by Corona688
Code:
( head -n 1 a.txt
tail -n +2 b.txt ) > c.txt

If this solution doesn't work for you, please explain why instead of repeating your question.
# 5  
Old 06-27-2012
Please be specific with your question. How do you want to find the line in first file, is it by pattern or line number and which line should get replaced in 2nd file???
# 6  
Old 06-27-2012
Code:
ex -s a.txt <<EOF
   1 d
   0 r !head -1 b.txt
   wq
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find replace text in xml file on the fly

Dear Unix guru, I have a .XML file which is being used to load data to oracle. This file comes on unix box and one of the tag in xml is oracle key word. I want to find that tag and replace with new tag on the fly For example I will get one of the tag in xml is as below <from>Test Test... (12 Replies)
Discussion started by: guddu_12
12 Replies

2. UNIX for Beginners Questions & Answers

Find and replace a string in a text file

Dear all, I want to find all the "," in my text file and then replace the commas to a tab. I found a script online but I don't know how to modify the script for my case. Any one can help? Thank you. @echo off &setlocal set "search=%1" set "replace=%2" set "textfile=Input.txt" set... (2 Replies)
Discussion started by: forevertl
2 Replies

3. Shell Programming and Scripting

How to find text and replace next line.?

Have multiple files with the same format and certain text is the same. Have specific text to search for and then need to replace the next line. Can search on the text DEVICE and multiple lines will be found. The line after each DEVICE line has {. Want to replace the line { with {-someadditiontext.... (2 Replies)
Discussion started by: bigdaddywags
2 Replies

4. Shell Programming and Scripting

Find and replace last line in a file

Hi I am having a file which has like this content shown below Aaa,bb,cc,dd Xxx,yy,d,12 Dodd,12-Jun,t I need to replace last line like this Aaa,bb,cc,dd Xxx,yy,d,12 Dodd,10-August,t (13 Replies)
Discussion started by: rohit_shinez
13 Replies

5. UNIX for Dummies Questions & Answers

Script to find line in one file and replace in another

Hey Guys, im looking for a script that will work under OSX. What i want to do is copy information from one file (Specific LIne) and write it to a certain line in another. To be more specific... I want the hostname of a mac to be gathered ( i assume its stored in a .plist file somewhere) and... (2 Replies)
Discussion started by: padgo
2 Replies

6. Shell Programming and Scripting

find from file and replace with specific text

Dear All, I do not have any knowledge of scripting. I want to replace specific lines of a text file with a specific text. Like I have one file which is "original file" and one file "changes file" which has list of lines which I want to replace in original file with a specific string. I want the... (5 Replies)
Discussion started by: libras
5 Replies

7. Shell Programming and Scripting

find and replace a line in a file

Hi, I am want find and replace in following content in the file. i want to repalce a word TABLESPACE XCRM_<ANY_CHAR> to TABLESPACE XCRM Sample File to Replace : LOB(COMPLEX_VALUE) STORE AS ( TABLESPACE XCRM_MED_D_NEW STORAGE(INITIAL 64K BUFFER_POOL DEFAULT) ENABLE... (3 Replies)
Discussion started by: gavemani
3 Replies

8. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

9. UNIX for Dummies Questions & Answers

Replace line of text in a file

I need to change the first line a file from "HDR,{any_number}",,,,, where {any_number} is incremental for each file to HDR,{any_number} Can someone please suggest an easy way please Regards Col (3 Replies)
Discussion started by: colinchase
3 Replies

10. UNIX for Dummies Questions & Answers

replace text in a file from the command line...

I am having to do a lot of searching thru files to replace words. Is there a command that i can run that will alow me to hunt thru a group of files and replace one word with another without having to open each file idividually? -thanks;) (1 Reply)
Discussion started by: dudboy
1 Replies
Login or Register to Ask a Question