Sponsored Content
Top Forums Shell Programming and Scripting Replace a word with string from another file Post 302291493 by rubin on Wednesday 25th of February 2009 08:59:33 PM
Old 02-25-2009
It's not too clear what's your expected final output ..., anyway try to modify the following code:



Code:
$ cat file_1
./1999 | 1999| 1999 | author | mail/01 | 01 | 01 | author | mail/<title> | file1.html | file1.html | author | mail
./1999 | 1999| 1999 | author | mail/ 01 | 01 | 01 | author | mail/<title>|  file2.html | file2.html | author | mail
./2000  | 2000| 2000 | author | mail/<title> | file1.html | file1.html | author | mail
./2000 | 2000| 2000 | author | mail/<title> | file2.html | file2.html | author | mail
./<title> | file1.html | file1.html | author | mail
./<title> | file2.html | file2.html | author | mail


Code:
$ cat file_2
Sitetitle 1
Sitetitle 2
Sitetitle 3
Sitetitle 4
Sitetitle 5
Sitetitle 6


Code:
 awk ' { if( ( getline rec < "file_2" ) > 0 ) sub(/<title>/,rec) } 1' file_1


Output:

Code:
./1999 | 1999| 1999 | author | mail/01 | 01 | 01 | author | mail/Sitetitle 1 | file1.html | file1.html | author | mail
./1999 | 1999| 1999 | author | mail/ 01 | 01 | 01 | author | mail/Sitetitle 2|  file2.html | file2.html | author | mail
./2000  | 2000| 2000 | author | mail/Sitetitle 3 | file1.html | file1.html | author | mail
./2000 | 2000| 2000 | author | mail/Sitetitle 4  | file2.html | file2.html | author | mail
./Sitetitle 5 | file1.html | file1.html | author | mail
./Sitetitle 6 | file2.html | file2.html | author | mail

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace word in a file

there are 300 files in a directory , some of these files has a word "error" , I word to change this word to "message" , can advise what can i do ? thx. (5 Replies)
Discussion started by: ust
5 Replies

2. Shell Programming and Scripting

Replace a word from a string

How can i replace a particular word from string i.e. var="shiv_dutt_para_shar" wrd="para" rep_wrd="PARA" what i am trying to do that first i'll search if $var catains #wrd or not. if it contains then i've to replace $wrd with $rep_wrd. I have tried following #!/bin/sh t="shiv... (5 Replies)
Discussion started by: jadoo_c2
5 Replies

3. UNIX for Dummies Questions & Answers

Seach for part of string and replace whole word

I am trying to find words in a text with a certain ending with sed and replace them with themselves but wrapped in tabs ex.: The fish swims in the water. -> searching for -ms ending The fish <tab>swims<tab>in the water. I've been trying all sorts of commands and get either an error... (5 Replies)
Discussion started by: stinnes
5 Replies

4. Shell Programming and Scripting

Replace a word After a string.

Hello Gurus, I have a file which has foll contents scattered: ,TotUnasgndNetAmt FROM DEV_EIS_T.Wkly_SO_CCD_MOSumSnpsht WHERE CalDayRunDt = '2010-07-21' UNION ALL SELECT CalDayRunDt ,BusWkCd ,'N' I want to replace 2010-07-21 that starts after ' and ends before... (8 Replies)
Discussion started by: indrajit_u
8 Replies

5. Shell Programming and Scripting

Replace first word after string INITIAL

Hi I have a file with hundreds of lines, some of the lines have word INITIAL followed by some numbers like ....INITIAL 1234535 .... ....INITIAL 5768644 .... I would like to replace the number after word INITLA with 4K how can I do it? Cant get my heard around this! The string is always... (3 Replies)
Discussion started by: halacil
3 Replies

6. Shell Programming and Scripting

Replace a word after a particular word in a file

Hi, I want to replace a word in a file which occurs after a particular word. For example : $cat file.txt CASE WHEN AND c1 = 'I' AND c2= '2' THEN 1 WHEN AND c1= 'I' AND c2= '0' THEN 2 So in this example i want to replace... (4 Replies)
Discussion started by: ashwin3086
4 Replies

7. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

8. Shell Programming and Scripting

Replace a word in a string starting with another word

Hi All, I have a file in which a number of lines are starting with similar first word but different next words. I want to replace the any nth word(not 1st or 2nd) with another word. Eg:- My file contains are like this:- Ram is a boy. Ram is a good boy. Ram plays cricket. Here I want to... (2 Replies)
Discussion started by: mukeshbaranwal
2 Replies

9. Shell Programming and Scripting

Search and replace the string with new word using xml tags

Hi All i need to replace the url1 inside <remote> tag in below xml in first instance and in the second instance with url2. any help appreciated <locations> <hudson.scm.SubversionSCM_-ModuleLocation> <remote>https://svn2015.com/svn/repos/internalshard</remote> ... (4 Replies)
Discussion started by: madankumar.t@hp
4 Replies

10. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies
HXCOPY(1)							  HTML-XML-utils							 HXCOPY(1)

NAME
hxcopy - copy an HTML file and update its relative links SYNOPSIS
hxcopy [ -i old-URL ] [ -o new-URL ] [ file-or-URL [ file-or-URL ] ] DESCRIPTION
The hxcopy command copies its first argument to its second argument, while updating relative links. The input is assumed to be HTML or XHTML and may be slightly reformatted in the process. If the second argument is omitted, hxcopy writes to standard output. In this case the option -o is required. If the first argument is also omitted, hxcopy reads from standard input. In this case the option -i is required. OPTIONS
The following options are supported: -i old-URL For the purposes of updating relative links, act as if old-URL is the location from which the input is copied. If this option is omitted, the actual location of the first argument is used for calculating relative links. -o new-URL For the purposed of updating relative links, act as if new-URL is the location to which the input is copied. If this option is omitted, the actual location of the second argument is used for calculating relative links. ENVIRONMENT
To use a proxy to retrieve remote files, set the environment variables http_proxy and ftp_proxy. E.g., http_proxy="http://localhost:8080/" BUGS
Unlike the last argument of cp(1), the last argument of hxcopy must be a file, not a directory. The second argument must be a local file. Writing to a URL is not yet implemented. To work around this, replace hxcopy file.html http://example.org/file.html by hxcopy -o http://example.org/file.html file.html tmp.html and then upload tmp.html to the given URL with some other command, such as curl(1). The first argument, however, may be a URL. hxcopy will download the given file. (Currently only HTTP is supported.) EXAMPLE
Assume the HTML file foo.html contains a relative link to "../bar.html". Here are some examples of commands: hxcopy foo.html bar/foo.html The file foo.html is copied to ../bar/foo.html and the relative link to "../bar.html" becomes "../../bar.html". hxcopy foo.html ../foo.html The file foo.html is copied to ../foo.html and the relative link to "../bar.html" is rewritten as "bar.html". hxcopy -i http://my.org/dir1/foo.html -o http://my.org/foo.html file1.html file2.html The file file1.html is copied to file2.html and the relative link to "../bar.html" is rewritten as "bar.html". A command like this may be useful to update files that are later uploaded to a server. SEE ALSO
cp(1), curl(1), hxwls(1) 6.x 9 Dec 2008 HXCOPY(1)
All times are GMT -4. The time now is 08:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy