The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace a word in a file only first 10 occurances nawazkhan77 Shell Programming and Scripting 4 11-12-2008 05:48 AM
how do I replace a word in a file using DOS commands?? sabithareddym Windows & DOS: Issues & Discussions 1 05-22-2008 12:17 AM
Replace word in a file sasiharitha UNIX for Dummies Questions & Answers 3 12-05-2007 01:11 AM
replace word in a file ust Shell Programming and Scripting 5 11-30-2007 08:03 PM
How to replace a word with a series of words in a file brap45 Shell Programming and Scripting 2 02-21-2006 02:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-25-2009
Tonda Tonda is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 5
Thumbs up Replace a word with string from another file

Hi,

this belongs a little to my other post [1] but only at the starting point.

With
Code:
find -name "*.htm*"
i got a list like this:

Code:
./1999/01/file1.html
./1999/01/file2.html
./1999/02/file1.html
./2000/04/file1.html
./2000/04/file2.html
./2000/04/file3.html
./2000/file1.html
./2000/file2.html
./file1.html
./file2.html
./file3.html
Then i wrote a awk script who gives me this output:

Code:
./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
Now i need to replace the "<title>"-part with the real content between the <title>-tag of this file.

I fetch the content with another script:

Code:
for i in `find -name "*.htm*"`
do
    awk -F'<title>' -v RS='</title>' 'RT{print $NF}' $i
done
and put the output in a file "titles.txt":

Sitetitle 1
Sitetitle 2
Sitetitle 3
...

So, now i have two files who have the same number of lines. How i could replace <title> with Sitetitle 1 ?

It this the right way with two files or its better to fetch the content of <title>-tag in the first script?

Thanks in advance
Stefano

[1] Insert Tabs / Indent text

Last edited by Tonda; 02-26-2009 at 08:24 AM.. Reason: Fix a typo in title
  #2 (permalink)  
Old 02-25-2009
rubin's Avatar
rubin rubin is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2007
Posts: 321
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
  #3 (permalink)  
Old 02-26-2009
Tonda Tonda is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 5
Thumbs up [Solved]

Hi,
thats exactly what i want to get.

Thanks rubin
Closed Thread

Bookmarks

Tags
awk, replace, two files

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0