The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
help required for replacing text in vi Chandu2u Shell Programming and Scripting 6 01-26-2008 11:12 AM
replacing a nul field with text DarkHound Shell Programming and Scripting 3 09-04-2007 03:34 PM
Replacing text chrchcol Shell Programming and Scripting 3 07-25-2006 01:30 PM
replacing text ajaya Shell Programming and Scripting 2 04-12-2006 01:31 PM
replacing text in an ascii doc cubs0729 Shell Programming and Scripting 6 09-29-2005 04:05 AM

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 06-13-2008
lotto_123 lotto_123 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Help in replacing text with the value of a variable

Input file - tmp

<begin>
./00003/
./00004/
<end>

I would like to replace "." with the value of pwd

so that the output will look like

/dev/project/00003/


t=`pwd`
sed -e "s/\./$t/g" tmp > tmp1;

The above piece of code is not working. Appreciate your help.
  #2 (permalink)  
Old 06-13-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Code:
t=`pwd`
sed -e 's/\./'${t}'/g' tmp > tmp1;
  #3 (permalink)  
Old 06-13-2008
lotto_123 lotto_123 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
It is still throwing the error.

sed: 0602-404 Function s/\.//dev/project/g cannot be parsed.
  #4 (permalink)  
Old 06-13-2008
awasthi_vish awasthi_vish is offline
Registered User
  
 

Join Date: May 2008
Posts: 1
use this

Quote:
Originally Posted by lotto_123 View Post
Input file - tmp

<begin>
./00003/
./00004/
<end>

I would like to replace "." with the value of pwd

so that the output will look like

/dev/project/00003/


t=`pwd`
sed -e "s/\./$t/g" tmp > tmp1;

The above piece of code is not working. Appreciate your help.



use this

set file name as command line arg

cat $1 | while read line
do
grep "./" $1
if [ $? -eq 0 ]
then
rep=${line/.\//$PWD/}
echo $rep >>tmp1
else
echo $line >>tmp1
fi
done
exit 0
  #5 (permalink)  
Old 06-13-2008
lotto_123 lotto_123 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
I corrected it on my own with the below code...

t=`pwd`
sed -e "s|\.|$t|g" tmp1 > tmp;

it worked...

Folks, thanks for your responses...
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 01:04 AM.


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