sed help

Hi,

I have a many xls file under a given directory and each file contains a line "href=a.xls"( which is different for diff files) as one of the line.
file:
----
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="XSLT Namespace" version="1.0">
<xsl:include href="a.xls"/>.

Now I need to do the following
*. search the pattern, "<xsl:include href="
*. Obtain the file name , which happens to be "a.xls"
*. Edit "a.xls" to "a_tmp.xls"
*. write back the modified file to the original file.

I tried
sed -e 's/<xsl:include href= \([^]*\).*/include href=\1_tmp.xls;\n&/' fileOne.xsl

but it throws error "cannot parse".

Any pointer will be of great help.

Cheers

Hello,

Per our forum rules, all threads must have a descriptive subject text. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

The reason for this is that nearly 95% of all visitors to this site come here because they are referred by a search engine. In order for future searches on your post (with answers) to work well, the subject field must be something useful and related to the problem!

In addition, current forum users who are kind enough to answer questions should be able to understand the essence of your query at first glance.

So, as a benefit and courtesy to current and future knowledge seekers, please be careful with your subject text. You might receive a forum infraction if you don't pay attention to this.

Thank you.

The UNIX and Linux Forums

The following seems to work:

sed 's/<xsl:include href="\([A-Za-z]*\)/<xsl:include href="\1_tmp/' fileOne.xls

The expression "[A-Za-z]" assumes filenames (excluding the ".xls" part) have only alphabetic characters. If they can contain other characters you should modify this expression to describe them.

see sed section on addresses, which says sed works on input lines.

Hi,
Thanks a lot .

I observed that it works for well formatted file. In one of the server I had the file where in the content of the file is in single line( cannot open the file from vi, vi says line too long). When I executed the same sed command on this file, it dumps nothing to the file, where in when i executed the same sed on my system having well formated file( means to say it has multiple lines) it works fine.

As far as i know, sed should work irrespective of file format , but reality it doesnt !!
Any pointer will be of great help

---------- Post updated 07-14-09 at 11:36 AM ---------- Previous update was 07-13-09 at 08:15 PM ----------

In the man page, its mentioned that "
"The hold space is limited to 8192 characters."
Is this the reason for sed to fail to perform the task mentioned in previous post....

---------- Post updated at 09:51 PM ---------- Previous update was at 11:36 AM ----------

It worked finally , after appending "\n" to the file... :slight_smile: