The UNIX and Linux Forums  


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
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 07:11 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
String Search & Replace IwishIknewC UNIX for Dummies Questions & Answers 1 03-25-2006 06:28 AM
Search and replace string between 2 points whited05 Shell Programming and Scripting 3 10-11-2005 03:05 PM
string search replace krishna UNIX for Advanced & Expert Users 1 12-19-2001 01:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-06-2006
mjs3221 mjs3221 is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 7
Need to replace all occurences of a search string using sed

All,

Here is what I am searching for using sed.

1 00640000106798

I want to replace that with the following.

8 0064B0000106798

I can do this easy enough from the command line using sed but I need to put the search string in a file and then execute the sed command within a shell script. I think the problem has something to do with how the spaces are being evaluated when reading from the file as the search string is never being found. Here is what I have so far. Please Help!!

cat $1 | while read LINE
do
echo $LINE > LINE.out

firstVar=$(awk -F" " '{print $1}' LINE.out)
secondVar=$(awk -F" " '{print $2}' LINE.out)
space=" "

testVar=${firstVar}$space${secondVar} #This makes the string 1 00640000106798

When I execute the following line the search string is never found.


sed 's/"$testVar"/8 0064B0000106798/g' WhatIf_4_Forecast.dat > tester.dat
  #2 (permalink)  
Old 12-07-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

Code:
sed "s/"$testVar"/8 0064B0000106798/g" WhatIf_4_Forecast.dat > tester.dat

Change single quotes to double quotes
  #3 (permalink)  
Old 12-07-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by anbu23
Code:
sed "s/"$testVar"/8 0064B0000106798/g" WhatIf_4_Forecast.dat > tester.dat

Change single quotes to double quotes
And drop the double quotes surrounding $testVar
Closed Thread

Bookmarks

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 03:21 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