LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-10-2004, 05:29 PM   #1
Burgin
Member
 
Registered: Apr 2004
Posts: 54

Rep: Reputation: 15
Using Sed under CMD.exe (windows)


I've been looking for a utility to so a simple search and replace string so I downloaded Sed from http://unxutils.sourceforge.net/.

What I want to do is actually a search and replace on Pathname and I want to pass a CMD environment like %HOMEPATH% or %CD%.

But the problem arises becuase Sed sees the single slashes in those environment as delimeters.

Is there anyway to work around this?

I don't have to use Sed, but I want it to be a small self contained executable. I don't want to install a full blown scripting language like Perl or Python just to do this.
 
Old 11-10-2004, 05:44 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
You can use (almost) any delimiter in s commands:

This:
Code:
sed -n 's/^searchstring/foundstring/p' file.txt
..does the same thing as:
Code:
sed -n 's,^searchstring,foundstring,p' file.txt
..or:
Code:
sed -n 's|^searchstring|foundstring|p' file.txt
This doesn't work though:
Code:
sed -n '|searchstring|p'
because this is not an s command. Should be possible to work around this, I guess.

Last edited by Hko; 11-10-2004 at 05:46 PM.
 
Old 11-23-2004, 01:52 PM   #3
Burgin
Member
 
Registered: Apr 2004
Posts: 54

Original Poster
Rep: Reputation: 15
The problem is that even if you use another delimiter, it still won't treat the single '\' as a literal. It still treats this as some kind of operand.

I guess sed doesn't work with variables that contain a path name.. I guess I have to try something else.
 
Old 11-23-2004, 02:05 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
You could pipe through tr and replace the slashes (which
to sed indeed are escape characters) with "|" for example,
and then do the search and replace, and tr again afterwards.


Cheers,
Tink
 
Old 11-26-2004, 03:14 PM   #5
Burgin
Member
 
Registered: Apr 2004
Posts: 54

Original Poster
Rep: Reputation: 15
Thanks, you pointed me in the right direction. I had to figure out what 'tr' was. It turned out to be in the list of WIN 32GNU utilities as well. However, I had to use '?' as the delimiter because it was the only character that was neither a) an operand for the 'tr' or 'sed' nor b) a legal character for a windows file/folder name.

To get this to work, I had to do something like

echo set WINPATH_TR=%WINPATH%|tr '\\' '?' > WINPATH_TR.bat
call WINPATH_TR.bat
del WINPATH_TR.bat

This would then set WINPATH_TR to something like c:?windows?system which I could pass down to sed.

(I'm not familiar with the affero)

Last edited by Burgin; 11-26-2004 at 03:17 PM.
 
Old 11-26-2004, 03:17 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Congratulations :)


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
equivalent Linux command for windows start cmd alix123 Programming 4 11-16-2008 07:06 PM
Windows question, winlogon.exe... sorry... ;) itsjustme General 4 09-27-2004 12:03 AM
I would like to open up windows.exe files bruce1271 Linux - Software 5 01-20-2004 08:36 PM
If *.exe for Windows what is for LinuX? Nukem Linux - Newbie 4 10-05-2003 06:23 AM
Can I compile a windows .exe? odious1 Linux - Software 6 08-29-2003 12:36 PM


All times are GMT -5. The time now is 02:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration