Sponsored Content
Top Forums Shell Programming and Scripting search and replace exact string Post 302531002 by skizim on Wednesday 15th of June 2011 03:15:12 PM
Old 06-15-2011
search and replace exact string

Hello Everyone,

Im trying to run a search and replace of exact strings and the strings that im using variables that are passed through an array in a while loop. Here is a snip of my code:
Code:
USEROLD=`cat oldusers`
USERNEW=`cat newusers`
USEROLDARRAY=( $USEROLD )
USERNEWARRAY=( $USERNEW )
arraylength=`cat oldusers | wc -l`
i=0;
while [ "$i" -lt "$arraylength" ]
do
        fromold=${USEROLDARRAY["$i"]};
        fromnew=${USERNEWARRAY["$i"]};
        echo "Replacing $fromold with $fromnew"
        cat groups.almost | sed s/$fromold/$fromnew/g >> tmpfile
        mv tmpfile groups.almost
 
let "i = $i +1"
done
mv groups.almost groups.final

in the oldusers file there is a list of users which some of them have their name in part or other users names so doing a replacment of say the user "lin" with "xlin" has resulted in replacing a user that had the word "lin" in their user name like "maklin" and maklin ends up being "makdlin". I also tried adding \b around my $fromold variable but no such luck. Anyone have an idea? Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I search a File for a string exact match

Hi, Can you help please. I have the following comand: if ]; then l_valid_string="Y" fi The problem I am trying to solve is that my l_string = ABC and my file contains ABC ABC_EFG I only want back the value ABC exact match. (3 Replies)
Discussion started by: CAGIRL
3 Replies

2. UNIX for Dummies Questions & Answers

grep exact string/ avoid substring search

Hi All, I have 2 programs running by the following names: a_testloop.sh testloop.sh I read these programs names from a file and store each of them into a variable called $program. On the completion of the above programs i should send an email. When i use grep with ps to see if any of... (3 Replies)
Discussion started by: albertashish
3 Replies

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

4. Shell Programming and Scripting

Search for exact string

Hi All, I need to search in a csv file as mentioend in the Appendix A for a exact word lets "TEST". But using teh below command iam getting TEST1234, TEST12 and otehr entries as well. the problem is i check this condition to check to add a record to a table by making sure it does not... (16 Replies)
Discussion started by: rahman_riyaz
16 Replies

5. Shell Programming and Scripting

Urgent help needed !!!....to replace a exact string

Hi experts, As i am a novice unix player...so need help for the below query...banged my head from quite a while...:confused: i have a set of html files, in which i need to search for string "Page"(case sensitive) and then replace the same with some numeric code ,say, "XXX1234". Here in... (1 Reply)
Discussion started by: rahulfhp
1 Replies

6. UNIX for Advanced & Expert Users

Search for an exact string in a Terminal

Is there hopefully a way to search for an exact string in Man Pages? I know if I want to search for anything containing -c I can just do this. /-c How would I search for "-c"? I want only "-c" to show up. So I tried this. /"-c" It took me literally and looked for the quotes also. (13 Replies)
Discussion started by: cokedude
13 Replies

7. Shell Programming and Scripting

Exact Search and Replace using AWK

Hello. I have written the following script to search and replace from one file into another. #awk script to search and replace from file a in file b NR == FNR { A=$2; next } { for( a in A ) sub(a, A)}1 file2 file1 While the function works pretty well, I want a. The word in File 2 to... (8 Replies)
Discussion started by: gimley
8 Replies

8. Shell Programming and Scripting

How to use SED or AWK to search and replace an exact string

I have a file DS1 DDS DS I want to replace only "DS" to "DSmail.blah.com" in a lot of files. I tried sed 's/DS/DSmail.blah.com' but it changes all the lines . thanks in advance (2 Replies)
Discussion started by: gubbu
2 Replies

9. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

10. Shell Programming and Scripting

Issue with sed command does not replace exact string matched

I have a file change.sed more change.sed I fire the below command inorder to replace "190.169.11.15" with "10.4.112.240" in proxy.logsed -f change.sed proxy.log proxy.log has the below entry more proxy.log The command replaces both 190.169.11.15 & 190.169.11.155 as below: I am expecting... (17 Replies)
Discussion started by: mohtashims
17 Replies
SUBSCRIPTIONS(5)					    InterNetNews Documentation						  SUBSCRIPTIONS(5)

NAME
subscriptions - Default recommended subscriptions DESCRIPTION
The pathetc/subscriptions file contains a list of newsgroups that is returned by the NNTP command LIST SUBSCRIPTIONS. Clients that support this command usually send it the first time they connect to a new news server. They use the returned list to initialize the list of subscribed newsgroups. The subscriptions file therefore should contain groups intended for new users, for testing, or that contain FAQs and other useful information for first-time Usenet users. The syntax of the subscriptions file is trivial; it is a simple list of newsgroup names, one per line. The order of newsgroups may be significant; the news reading client may present the groups in that order to the user. Be aware that use of the LIST SUBSCRIPTIONS command is not widespread (though documented in RFC 6048) and most news clients will never ask for this file. EXAMPLE
A typical subscriptions file may look like: news.announce.newusers news.newusers.questions local.test local.general local.talk misc.test misc.test.moderated news.answers news.announce.newgroups This gives the client the FAQs and question newsgroup for new users first, then a local newsgroup for testing and various commonly-read local discussion groups, followed by the world-wide test groups, all the FAQs, and announcements of new world-wide newsgroups. If there is a local new users group, one might want to list it first. HISTORY
Written by Bettina Fink <laura@hydrophil.de> for InterNetNews. $Id: subscriptions.pod 9138 2010-10-29 18:09:50Z iulius $ SEE ALSO
nnrpd(8). INN 2.5.3 2011-06-10 SUBSCRIPTIONS(5)
All times are GMT -4. The time now is 04:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy