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
Replacing nulls using sed novice1324 Shell Programming and Scripting 7 02-27-2008 03:56 AM
help in replacing ?? zedex Shell Programming and Scripting 5 08-31-2007 02:45 AM
Replacing in SED superprogrammer Shell Programming and Scripting 8 07-11-2006 03:33 AM
replacing corrupt /tmp dir.. moxxx68 UNIX for Advanced & Expert Users 6 05-28-2005 07:58 PM
replacing \n by \r\n crashnburn UNIX for Dummies Questions & Answers 3 11-24-2003 03: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 04-09-2004
oldtrash oldtrash is offline
Registered User
  
 

Join Date: Jul 2003
Location: india
Posts: 20
replacing with `pwd`

Hi E(uni)xperts,

I have a file in which I need to replace some text with the current path of the execution.

meaning..

if I am running from

/user/oldtrash/scripts and the file contains

"this is ur directory current_dir"

then I should see the file content as

"this is ur directory /user/oldtrash/scripts"


Any ideas?

Thanks,
OldTrash
  #2 (permalink)  
Old 04-09-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
you answered your own question in the subject of this thread.

just make that text file executable.
  #3 (permalink)  
Old 04-09-2004
oldtrash oldtrash is offline
Registered User
  
 

Join Date: Jul 2003
Location: india
Posts: 20
Hi Optimus,
Thanks for the reply.
I forgot to mention my trials with sed and perl..

I tried

old>sed -e "s/current_dir/`pwd`/" < old_file > new_file
sed:command garbled: /current_dir//user/oldtrash/scripts/

old>perl -e "s/current_dir/`pwd`/" < old_file > new_file
Bareword found where operator expected at -e line 1, near "s/current_dir//user"
syntax error at -e line 1, near "s/current_dir//user"
Bareword found where operator expected at -e line 1, near "Oldtrash"
(Missing operator before Oldtrash?)
Execution of -e aborted due to compilation errors.



OldTrash
  #4 (permalink)  
Old 04-09-2004
pressy's Avatar
pressy pressy is offline Forum Staff  
solaris cultist
  
 

Join Date: Aug 2003
Location: Vienna / Austria (Europe) [EARTH]
Posts: 726
............

why don'T you use the shell variable:

$PWD

?

Last edited by pressy; 04-09-2004 at 06:36 PM..
  #5 (permalink)  
Old 04-09-2004
oldtrash oldtrash is offline
Registered User
  
 

Join Date: Jul 2003
Location: india
Posts: 20
No luck!
  #6 (permalink)  
Old 04-09-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
i thought you ment you already had in place of current_dir teh pwd command.

didnt know you were trying to sub it on the fly.

dont use the forward slash in your sed command choose another metachar like pipe.

ie: sed "s|current_dir|`pwd`|" <filename>

that works on my sys
  #7 (permalink)  
Old 04-09-2004
oldtrash oldtrash is offline
Registered User
  
 

Join Date: Jul 2003
Location: india
Posts: 20
Thanks Optimus,
It worked.

Thanks Pressy for looking into this.

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 10:06 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