SED question 
Author Message
 SED question

Hi Unix & Awk programmers,
I am unsure where to post this question so let me know if there is a
more appropriate group. In any case I think one of you may know the
answer to this one:

I have a sed script if a file (using sed -f arg) that looks somewhat
like this which allows me to have a bunch of sed commands that apply
only to functions with _test at the end of the function name. The
example below is a sketch of what I am doing (in my case, the MYTYPE_T
matches the header lines and "}" in column one matches the end of the
function).

/_test(MYTYPE_T/,/^}/{
  s/doThisTestProcess/xxx_doThisTestProcess/

Quote:
}

However, I want the 'xxx' to be tied to the initial prefix of the
function name and use that variable in the sed command(s) which are
nested. I am having trouble figuring out how to do this... it seems that
the inner sed commands may have their own "environment" such that
whatever I try to hold on to is lost. Here is what I would like to be
able to do...

/(.*)_test(MYTYPE_T/,/^}/{
  s/doThisTestProcess/${1}_doThisTestProcess/

Quote:
}

Any idea on how to do this... much thanks in advance (please send reply
to me + the newsgroup).

Jim Jones



Sat, 05 Oct 2002 03:00:00 GMT  
 SED question


Quote:
> Hi Unix & Awk programmers,
> I am unsure where to post this question so let me know if there is a
> more appropriate group. In any case I think one of you may know the
> answer to this one:

Ummm, this group is populated with many people that really like to
help. That makes it an appropriate group in some way. But I bet you
would reach more sed knowledge if you tried comp.unix.shell. There's a
dude there named Ken Pizzini who's a real sed wizard if ever there was
one!

I read your problem desccription and I know it's doable in sed,
somewhat the way you tried. But I know not enough sed to help you. =(

/PEZ
--
-= Spam safe(?) e-mail address: pez at pezius.com =-

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 05 Oct 2002 03:00:00 GMT  
 SED question
Hi Dude,

I think I got an approach here:

use a shell script.
use a shell script variable to equal whatever "xxx" is.
embedd the sed part in the shell script, and refer to
s/doThisTestProcess/${1}_doThisTestProcess/

Maybe In your shell script:
#!/bin/sh
#

x=$(cat File)
y=$(echo "$x" |  sed -n "/_test(MYTYPE_T/p" | cut -d"_" -f1)
echo "$x" | sed -n "/_test(MYTYPE_T/,/^}/ {
s/doThisTestProcess/${y}_doThisTestProcess/
p

Quote:
}"

#-----end of script-------#

I think you can also use the \1 in the s/// expression
so maybe, s/^\(.*\)_.*/${y}_\1/

say y="hello"
then echo "this_is a test" | sed "s/^\(.*\)_.*/${y}_\1/"
would I think output: "hello_this"

=================================================

On Tue, 18 Apr 2000 11:14:38 -0500, Jim Jones

Quote:

>Hi Unix & Awk programmers,
>I am unsure where to post this question so let me know if there is a
>more appropriate group. In any case I think one of you may know the
>answer to this one:

>I have a sed script if a file (using sed -f arg) that looks somewhat
>like this which allows me to have a bunch of sed commands that apply
>only to functions with _test at the end of the function name. The
>example below is a sketch of what I am doing (in my case, the MYTYPE_T
>matches the header lines and "}" in column one matches the end of the
>function).

>/_test(MYTYPE_T/,/^}/{
>  s/doThisTestProcess/xxx_doThisTestProcess/
>}

>However, I want the 'xxx' to be tied to the initial prefix of the
>function name and use that variable in the sed command(s) which are
>nested. I am having trouble figuring out how to do this... it seems that
>the inner sed commands may have their own "environment" such that
>whatever I try to hold on to is lost. Here is what I would like to be
>able to do...

>/(.*)_test(MYTYPE_T/,/^}/{
>  s/doThisTestProcess/${1}_doThisTestProcess/
>}

>Any idea on how to do this... much thanks in advance (please send reply
>to me + the newsgroup).

>Jim Jones




Mon, 07 Oct 2002 03:00:00 GMT  
 SED question
Thanks everybody,

The solutions seems to be clever use of h (hold) and later use of g,G, or
x. I got an answer from a guy named Pizzini in another group:

/pattern1/,/pattern2/{
    /pattern1/h
    ...
    /pattern3/{
      ...
      use of g, G, x, and/or other sed commands
      ...
      }
   }

I'm still not real clear on the scoping rules and such but I got what I needed.

Jim Jones



Sat, 26 Oct 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to do this.. (SED question)

2. a sed question

3. Sed Question

4. Urgent VI/SED question

5. This might be a sed question

6. sed question

7. A sed question

8. awk vs. sed question

9. A sed question

10. sed question: unreliable "/^$/d" ?

11. Newbie awk (sed??) question, regular expressions

12. Awk/Sed Filehandler question

 

 
Powered by phpBB® Forum Software