Sponsored Content
Top Forums UNIX for Advanced & Expert Users batch or wordlists search and replace Post 302086154 by zerobreach.com on Tuesday 22nd of August 2006 03:00:57 PM
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"
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
NNCHECK(1)						      General Commands Manual							NNCHECK(1)

NAME
nncheck - check for unread articles SYNOPSIS
nncheck [ -Q -r -t ] [ -f format ] DESCRIPTION
nncheck will report if there are some articles on the system which you have not read. Without options, nncheck will simply print a message reporting the number of unread articles with the following format: There are 327 unread articles in 25 groups and when there are no unread articles, the following message will be printed: No News (is good news) nncheck will exit with a value of 0 if there are unread articles, and 99 if there is no news (see the exception for the -r option.) It is important to notice that even though unread articles have been reported by nncheck, the actual number of unread articles may be much lower (or even zero) when nn is invoked to read the articles. This is because the calculation of the number of unread articles is only based on recorded article number intervals. Invoking nn to read the articles may reveal that the articles have previously been read in another news group, have been expired, or are killed using the auto-kill facility. The following options are used to modify the amount and format of the output from nncheck: -Q Quiet operation. No output is produced, only the exit status indicate whether there is unread news. -t Print the name of each group with unread articles, and how many unread articles there are (not counting split digests!). -r Output a single integer value specifying the number of unread articles, and exit with a 0 status (somebody told me this would be useful). -f format Output the number of unread articles using the specified format. The format is a text that may contain the following %-escapes: %-code resulting output %u "uuu unread articles" %g "ggg groups" %i "is" if 1 unread article, else "are" %U "uuu" %G "ggg" where uuu is the number of unread articles, and ggg is the number of groups with unread articles. For example, the default output format is "There %i %u in %g" which I prefer to the following less perfect format: "There are %U unread article(s) in %G group(s)" FILES
~/.newsrc The record of read articles $db/MASTER The database master index SEE ALSO
nn(1), nngoback(1), nngrab(1), nngrep(1), nnpost(1), nntidy(1) nnadmin(1M), nnusage(1M), nnmaster(1M) AUTHOR
Kim F. Storm, Texas Instruments A/S, Denmark E-mail: storm@texas.dk 4th Berkeley Distribution Release 6.6 NNCHECK(1)
All times are GMT -4. The time now is 08:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy