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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacing a line in a file - HELP!!! maxmave Shell Programming and Scripting 1 06-04-2008 11:55 PM
replacing the characters in a file trichyselva UNIX for Dummies Questions & Answers 2 01-03-2008 08:02 AM
replacing single space in argument convenientstore Shell Programming and Scripting 7 04-25-2007 01:02 PM
replacing few characters in a file purnakarthik UNIX for Dummies Questions & Answers 1 01-25-2007 05:17 PM
searching through a file and replacing Gerry405 UNIX for Dummies Questions & Answers 2 10-04-2005 08:29 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 02-26-2008
dsrookie dsrookie is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 12
Replacing URL in a file with space

Hi,

I have a file with a URL text written in it within double quotes e.g.

"http://abcd.xyz.com/mno/somefile.dtd"

I want the above text to get replaced by a single space character.

I tried

cat File1.txt | sed -e 's/("http)*(dtd")/ /g' > File2.txt

But it didnt work out. Can someone suggest an sed command which replaces this url text, including double quotes, with a space.

Thanks
  #2 (permalink)  
Old 02-26-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,300
Try this:

Code:
sed 's!^"http://abcd.*somefile.dtd"$! !' < File1.txt > File2.txt
Regards
  #3 (permalink)  
Old 02-27-2008
dsrookie dsrookie is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 12
Thanks....but the command didnt work.......it did not delete/replace

Regards
  #4 (permalink)  
Old 02-27-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,300
It works fine for me. Try this with the line you provide. It's substitute by an X instead of a space with the sed command:

Code:
echo '"http://abcd.xyz.com/mno/somefile.dtd"'|sed 's!^"http://abcd.*somefile.dtd"$!X!'
Regards
  #5 (permalink)  
Old 02-28-2008
dsrookie dsrookie is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 12
Hi Franklin,

The echo | sed works fine, but the moment i try to the same thing in the file it doesnt work.

SED works and substitutes text if I specify any other text/pattern (which doesnt have any wild character or forward slash)

cat file1.txt | sed -e 's/DOCTYPE/ /' > file2.txt

But somehow when I use wild characters in sed its not working. I can specify the url since it may change with time.

I have to remove the url from following stmt

<!DOCTYPE tag SYSTEM "http://someurl/fileabc.dtd">

Thanks
  #6 (permalink)  
Old 02-29-2008
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
To rephrase your problem: you search for a string of the form "http://...." enclosed in double quotes and ending in a white space, yes?

Further, we do not have to consider the end-of-line situation, as the URL will always be part of some HTML-tag and therefore cannot be at the end of the line. (Otherwise we would have to consider the two cases '"http://..." ' and '"http://...."$'.)

Then the solution is:

Code:
sed 's/"http:\/\/[^ ]*dtd"/ /' file1 > file2
The reason why you code didn't work was:

Code:
cat File1.txt | sed -e 's/("http)*(dtd")/ /g' > File2.txt
First, the bracket ("()") are just simple characters if you do not escape them: "\(...\)". As you have no brackets in your search string this must fail.

Second, even if that were grouping characters the asterisk ("*") after "http" would then make the whole group optional. "*" is not "any string" like in DOS, but "the last expression zero or more times".

So, what you have been searching for was: the literal string '("http' followed by an optional ')', followed by '(dtd")'.

I hope this helps.

bakunin
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 02:18 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