help on sed file 
Author Message
 help on sed file

Hi,
  I have a sed file that has a sequence of commands.

#sed file batch.sed
s|pattern1|value1|g
s|pattern2|value2|g
s|pattern3|value3|g
s|pattern4|value4|g
s|pattern5|value5|g
--
EOF

  When i do a
 sed -f batch.sed inputFile
 everything works fine. I want to tweak with this file to have more
functionality than just sed commands. (application driven ! cannot
help it)..
  I want to add more lines (say a text, perl code or any script) to
the end of the file, but the enduser should not be affected by this.
still if he does a sed -f <file> inputFile the result should be the
same.
  Ofcourse i can do this by having them as comments starting with #.
But this has got two implications
  1. The code that follows will have to be stripped off the leading
'#' sign and then interpreted,
  2. The code that follows will have to have a different notation for
comments

  Please advise me on how to go about this
Iam thinking of something like

  #sed file
  s|pattern1|value1|g
  s|pattern2|value2|g
  s|pattern3|value3|g
  s|pattern4|value4|g
  s|pattern5|value5|g  

  <logic that says "sed" need not worry here after>
  ## DELIMETER that separates the sed part from the rest

  any inforamtion i like to have
  abcdefghijk

  --
  EOF

  I have no difficulty in parsing the code when i look for the
required information, since i know the delimiting part that separates
the sed part from the rest i can easily separate that code. I face a
problem only when i sed that file.

Thanks and regards
Thens



Wed, 08 Jun 2005 13:37:33 GMT  
 help on sed file
Quote:

> Hi,
>   I have a sed file that has a sequence of commands.

[ ... ]

Quote:
>   I want to add more lines (say a text, perl code or any script) to
> the end of the file, but the enduser should not be affected by this.
> still if he does a sed -f <file> inputFile the result should be the
> same.

[ ... ]

Quote:
>   Please advise me on how to go about this
> Iam thinking of something like

>   #sed file
>   s|pattern1|value1|g
>   s|pattern2|value2|g
>   s|pattern3|value3|g
>   s|pattern4|value4|g
>   s|pattern5|value5|g  

>   <logic that says "sed" need not worry here after>
>   ## DELIMETER that separates the sed part from the rest

>   any inforamtion i like to have
>   abcdefghijk

>   --
>   EOF

What you should use is the 'b' (branch) command, which is
the sed equivalent of 'goto' command. 'b' can be followed by
a :label in sed, but if nothing follows the 'b', then sed
will jump to the end of the script.

So, your request is fairly easy:

   s|pattern4|value4|g
   s|pattern5|value5|g  
   b  
   # Everything below b is ignored.

   any inforamtion i like to have
   abcdefghijk

   --
   EOF

Hope this helps. And Merry Christmas!

--
Eric Pement



Sat, 11 Jun 2005 05:46:12 GMT  
 help on sed file

Quote:


> > Hi,
> >   I have a sed file that has a sequence of commands.
> [ ... ]

> >   I want to add more lines (say a text, perl code or any script) to
> > the end of the file, but the enduser should not be affected by this.
> > still if he does a sed -f <file> inputFile the result should be the
> > same.
> [ ... ]

> >   Please advise me on how to go about this
> > Iam thinking of something like

> >   #sed file
> >   s|pattern1|value1|g
> >   s|pattern2|value2|g
> >   s|pattern3|value3|g
> >   s|pattern4|value4|g
> >   s|pattern5|value5|g  

> >   <logic that says "sed" need not worry here after>
> >   ## DELIMETER that separates the sed part from the rest

> >   any inforamtion i like to have
> >   abcdefghijk

> >   --
> >   EOF

> What you should use is the 'b' (branch) command, which is
> the sed equivalent of 'goto' command. 'b' can be followed by
> a :label in sed, but if nothing follows the 'b', then sed
> will jump to the end of the script.

> So, your request is fairly easy:

>    s|pattern4|value4|g
>    s|pattern5|value5|g  
>    b  
>    # Everything below b is ignored.

>    any inforamtion i like to have
>    abcdefghijk

>    --
>    EOF

   I doubt if this works. b without a label will sure transfer the
control to the end of the file. But anything that follows b needs to
be a valid sed command. b will only make sure they are not  executed.
But still it needs to be a sed command. so it doesnt solve my problem.
I think i will have to stick to the usage of comments .

Thanks and regards
Thens

- Show quoted text -

Quote:
> Hope this helps. And Merry Christmas!



Sat, 11 Jun 2005 20:03:01 GMT  
 help on sed file

Quote:

>  I have a sed file that has a sequence of commands.

>#sed file batch.sed
>s|pattern1|value1|g
>s|pattern2|value2|g
>s|pattern3|value3|g

>  ....
>  I want to add more lines (say a text, perl code or any script) to
>the end of the file, but the enduser should not be affected by this.
>still if he does a sed -f <file> inputFile the result should be the
>same.
>  Ofcourse i can do this by having them as comments starting with #.

I don't think it is going to be quite as easy as you'd hope, and it
probably can't be made to work on unix. But if you are using MSDOS,
then a ctrl-Z character separating the sed script from your appended
text can be made to work. Editing a text file containing an embedded
ctrl-Z can be awkward, so I've used an ampersand, piping it through a

C:\> type sed.scr
#sed file batch.sed
s|pattern1|fox|g
s|pattern2|over|g
s|pattern3|lazy|g

The quick brown pattern1
Jumps pattern2 the pattern3 dog.



The quick brown fox
Jumps over the lazy dog.

So this works for me, but YMMV. To do something like this on a unix
platform you'd aim to transform that ctrl-Z into ctrl-D, but I have not
found I can make it work. SED reads past the ctrl-D and sees the whole
file.
--
John Savage            (for email, replace "ks" with "k" and delete "n")



Wed, 15 Jun 2005 04:05:07 GMT  
 help on sed file

Quote:

>  I have a sed file that has a sequence of commands.

>#sed file batch.sed
>s|pattern1|value1|g
>s|pattern2|value2|g
>s|pattern3|value3|g

>  ....
>  I want to add more lines (say a text, perl code or any script) to
>the end of the file, but the enduser should not be affected by this.
>still if he does a sed -f <file> inputFile the result should be the
>same.
>  Ofcourse i can do this by having them as comments starting with #.

As you say, you could *start* each line with # or, alternatively, you
could *end* each line with \ if that is any better. Example, using the
unconditional 'b' command to avoid the data:-

b;a\
ls -l somefile ; #\
date ; #\
echo what > file ; #\

etc.
--
John Savage            (for email, replace "ks" with "k" and delete "n")



Wed, 15 Jun 2005 04:07:36 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Sed: Inserting file in another file

2. sed: input file = output file

3. log file processing - awk or sed

4. Find the first occurence of file in pwd with sed

5. Using awk And/Or sed To Edit Fourth Field Of File

6. sed - extracting "*.cpp" from a file

7. SED multiple file redirection?

8. How to get info from a file with sed/awk/perl

9. deleting records in a file using AWK, SED, or kshell

10. Getting awk (or sed or anything else) to put single quotes into file

11. sed/awk script to format a file??

12. Need help with sed or awk !!

 

 
Powered by phpBB® Forum Software