![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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 |
|
||||
|
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 Code:
cat File1.txt | sed -e 's/("http)*(dtd")/ /g' > File2.txt
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|