Interesting question - Search and replace the word after sign "="


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Interesting question - Search and replace the word after sign "="
# 1  
Old 11-27-2009
Interesting question - Search and replace the word after sign "="

Hi Guys,

Req your help in searching and replacing the word that comes after equals(=) symbol

I would like to replace the sting in bold with a string in variable.

d=ABCDF8C44C22
# grep -i NIM_MASTERID ${_NIMINFO}
export NIM_MASTERID=00CDF8C44C00

I'm looking to replace any word that comes after "=" symbol in the above grep statement output.

like to see the output as export NIM_MASTERID=ABCDF8C44C22
after replacing export NIM_MASTERID=00CDF8C44C00


Thanks
# 2  
Old 11-27-2009
Try:

Code:
echo "export NIM_MASTERID=00CDF8C44C00" | sed 's/\(.*\)=.*/\1=ABCDF8C44C22/'

# 3  
Old 11-27-2009
slightly stronger: -
Code:
echo "export NIM_MASTERID=00CDF8C44C00" | sed 's/\(NIM_MASTERID=\).*/\1ABCDF8C44C22/'

# 4  
Old 11-27-2009
Code:
awk -v d="ABCDF8C44C22" 'BEGIN {FS=OFS="="} /NIM_MASTERID/ {$2=d}1' ${_NIMINFO}

# 5  
Old 11-27-2009
Code:
d=ABCDF8C44C22
# grep -i NIM_MASTERID ${_NIMINFO}|sed "s/=.*/=$d/"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

2. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

3. Linux

Linux command to find and replace occurance of more than two equal sign with "==" from XML file.

Please help me, wasted hrs:wall:, to find this soulution:- I need a command that will work on file (xml) and replace multiple occurrence (more than 2 times) Examples 1. '===' 2. '====' 3. '=======' should be replaced by just '==' Note :- single character should be replaced. (=... (13 Replies)
Discussion started by: RedRocks!!
13 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Awk to Search and Replace inside the pipe "|"

Hi, Anyone can help me on how to replace the qoutes inside the pipe | in my Text File like belows; "AAAA"|"Test "1-A""|"Test AAAA"|"This is A" "BBBB"|"Test "1-B""|"Test BBBB"|"This is B" "CCCC"|"My Test C"|"Test "CCCC""|"This is C" The output I need like belows; "AAAA"|"Test 1-A"|"Test... (12 Replies)
Discussion started by: fspalero
12 Replies

6. Shell Programming and Scripting

Script to search a string which is in between "" and replace it with another character

Hi, I am trying to search a string from a text file which is in between "" (Double Quotes) (Eg: "Unix"), and replace it with a | where ever it is appearing in the text file and save the file. Please help me. -kkmdv (6 Replies)
Discussion started by: kkmdv
6 Replies

7. UNIX for Dummies Questions & Answers

sed for "/7.*" search and replace

Hi , I have this file having thousands of records in it . I want to remove every 9 digit number starting with 7 in it . The few lines from the sample file are "/-GEO-Prizm-Dashes-Covers-Caps-Trim/720000100-200742232-600022761.car"... (8 Replies)
Discussion started by: capri_drm
8 Replies

8. Shell Programming and Scripting

sed: a "replace unless match" question

Context: I am using sed in a cronjob to change the dates in a separate sql script every week. Each week the dates must be updated to reflect the Monday and Friday of the previous week. I have solved the problem but in solving it I discovered a major weakness in my knowledge of sed. Lines to be... (0 Replies)
Discussion started by: Bubnoff
0 Replies

9. Shell Programming and Scripting

Additional question to "awk to replace particular field"

I guess it was getting a little messy on the other post so here goes: Link to previous post for Question: https://www.unix.com/shell-programming-scripting/111338-awk-replace-particular-field.html Continuation of Question hey i was messing around a bit ... made me wonder... If the... (1 Reply)
Discussion started by: VGR
1 Replies

10. Shell Programming and Scripting

replace word with using "sed" not work...

Hi, I have a xml text file with the following data, I would like replace F0</Number> to F</Number> only. i used sed to replace, but it not work!! anyone can help? <Number>11 20 03 22 23 21 91 00 F0</Number> <Number>12 20 03 20 99 21 91 20 F0</Number> <Number>10 21 03 21 78 21 92 27... (28 Replies)
Discussion started by: happyv
28 Replies
Login or Register to Ask a Question