batch or wordlists search and replace


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users batch or wordlists search and replace
# 1  
Old 08-22-2006
batch or wordlists search and replace

Hello Experts!

I've become perplexed Smilie as to why I can't get this to work and have given up the male "I can do it" attitude. I am asking the unix experts.

The script I am writing involves reading a file that contains thousands of keywords (not csv), just one line after another of keywords and keyword phrases. I am attempting to read each line and carry this "keyword variable" into sed or perl and search and replace the variables in a single file if found.

#!/bin/bash
set +v
IFS=$'\n'

for i in `cat wordlist.txt | dos2unix | sed -e 's/ *$//'`
do
#./mksr "$i" "\<a href=\"http:\/\/www.domain.com\"\>$i\<\/a\>" ./articles.txt
#perl -pi -e 's/search/replace/g' *.text
perl -pi -e 's@$i@<a href=http://www.domain.com>$i</a>@g' articles.txt
#cat articles.txt | sed -e 's@$i@<a href=http://www.domain.com>$i</a>@' > articles.tempfile
#cat articles.txt | tr '$i' '<a href=http://www.domain.com>$i</a>' > articles.tempfile
echo "<a href=http://www.domain.com>$i</a>"
done


------------wordlist-----------
dj
djs
dvd
card
free
ring
vows
bride
cakes
dress
-----------wordlist---------

-----------article-----------
Title: Beverages 101

Subhead: Wines for your Special Day

As the last note of recessional music fades into history and the last scrap of choice confetti (be it birdseed or rice) hits the earth, the guests rise from their seats and begin to scour the premises, all with one target on their minds ...
-----------article------------

What the heck am I doing wrong in the for loop?

Any help would be greatly appreciated! I've spend three days on this and can't seem to find one example on the internet of someone trying to do this. Lots of examples of how to do a single word sed s/blah/blah2/g on many files, but no multiple interactions of search and replace same file with a keyword lists!


...sorry I should have put this in shell programming
ugh!! Smilie

Last edited by zerobreach.com; 08-22-2006 at 04:03 PM.. Reason: Sorry, I should have put this in "shell programming"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: batch replace a portion of text in files

Hi all, What I would like to achieve is to batch change the code below in every pdf in a given directory (each pdf is uncompressed so that can be easily edited). An example of the javascript code: if (this.hostContainer) { try { this.hostContainer.postMessage(pp_216', 15259]);... (3 Replies)
Discussion started by: menteith
3 Replies

2. Shell Programming and Scripting

Nested search in a file and replace the inner search

Hi Team, I am new to unix, please help me in this. I have a file named properties. The content of the file is : ##Mobile props east.url=https://qa.east.corp.com/prop/end west.url=https://qa.west.corp.com/prop/end south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Discussion started by: tolearn
2 Replies

3. Shell Programming and Scripting

ksh : multiple for wordlists

Hi guys This is my first post on here and I am fairly new to ksh scripting, please be gentle! I am trying to create a script that takes an fssnap of all slices and then .tar's them. The trouble that I am having is with the .tar element, I want it to label the .tar based on which slice it is... (1 Reply)
Discussion started by: andy123
1 Replies

4. Shell Programming and Scripting

Sed or awk for batch replace file name

Can you please point me in the correct direction? I need a line or script to run though a given directory and find all files with "@domain.local" in there names and simple remove that. For example if the files were named 1234@domain.local the file would then become 1234. (1 Reply)
Discussion started by: binary-ninja
1 Replies

5. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

6. Shell Programming and Scripting

Batch rename files after internal search pattern

Hello all I am trying to do a script that would allow me to mass rename files after a grep search within them. They are XML files and the pattern I would like to append to the file name is easy to find (e.g. <filename>foo</filename>), but I can't for the life of me find out how to do it and... (2 Replies)
Discussion started by: aavv
2 Replies

7. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

8. Shell Programming and Scripting

use sed do batch wildcard string replace

Hi, Here is what I want to do I want to search local directory and its sub directory, all the files which contain any string like _12345, then remove this string. String is a combination of _ plus a random integer number. For example, here is one line in a file before <properties... (1 Reply)
Discussion started by: bp5000
1 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. Shell Programming and Scripting

batch or wordlist search and replace in one file

Hello Experts! I've become perplexed as to why I can't get this to work and have given up the male "I can do it" attitude. I am asking the unix experts. The script I am writing involves reading a file that contains thousands of keywords (not csv), just one line after another of keywords and... (1 Reply)
Discussion started by: zerobreach.com
1 Replies
Login or Register to Ask a Question