help me!! sed command.

help me!! sed command.

Post by somez7 » Wed, 18 Sep 2002 05:44:58



Hi ,all

I'm reading a book regarding linux.
I meet sed command as follows
    sed  's%\$(PERL)%/usr/bin/perl%'  Makefile > Makefile.backup
here I'd like to know the meaning of  1th % sign , 2nd % sign 3th % sign.
Could some explain me. what's the meaning of each % signs

Have a day.

 
 
 

help me!! sed command.

Post by Kasper Dupon » Tue, 17 Sep 2002 13:53:49



> Hi ,all

> I'm reading a book regarding linux.
> I meet sed command as follows
>     sed  's%\$(PERL)%/usr/bin/perl%'  Makefile > Makefile.backup
> here I'd like to know the meaning of  1th % sign , 2nd % sign 3th % sign.
> Could some explain me. what's the meaning of each % signs

It is a seperator indicating where the search string and replacement
string ends. The man page about sed just uses / as seperator, and
does not mention that other chars can be used as well. But it seems
that you can use almost any char as seperator. The sed command will
look on the first char after s and use that as the seperator. (Nice
to know that, now I don't have to escape all my / anymore.)

--
Kasper Dupont -- der bruger for meget tid p? usenet.



 
 
 

help me!! sed command.

Post by Eric P. McC » Tue, 17 Sep 2002 15:12:07



> I'm reading a book regarding linux.
> I meet sed command as follows
>     sed  's%\$(PERL)%/usr/bin/perl%'  Makefile > Makefile.backup
> here I'd like to know the meaning of  1th % sign , 2nd % sign 3th % sign.

You mean "1st, 2nd, and 3rd."

The second character in an "s" command is _always_ the delimiter.
That is, the command you give is:

  s     \$(PERL)        /usr/bin/perl

The first item is the command, the second is the regular expression
you are searching for, and the third is what you are substituting in.

You are probably more used to seeing sed's s-commands with forward
slashes for delimiters.  They didn't use them in this case because the
substitution expression has forward slashes in it.  But if you wanted
to, you could rewrite their sed expression like so:

  s/\$(PERL)/\/usr\/bin\/perl/

Which is not so clear, because you have to escape the forwrd slashes.

Quote:> Have a day.

Why?  What's wrong with them?

--

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj

 
 
 

help me!! sed command.

Post by Jim Fische » Wed, 18 Sep 2002 09:46:58



> Hi ,all

> I'm reading a book regarding linux.
> I meet sed command as follows
>     sed  's%\$(PERL)%/usr/bin/perl%'  Makefile > Makefile.backup
> here I'd like to know the meaning of  1th % sign , 2nd % sign 3th % sign.
> Could some explain me. what's the meaning of each % signs


command, e.g.,

    s/a/b/

    s%a%b%

For example, try searching for the string '/usr/bin/perl' using the s///
syntax:

     echo "/usr/bin/perl" | sed 's/\/usr\/bin\//hello /' -

This is too much work! :-\

But if you use a field delimiter character other than '/' with sed's 's'

command that manipulates input strings containing the '/' character:

     echo "/usr/bin/perl" | sed 's%/usr/bin/%hello %' -

--
Jim

To reply, please remove "_link" and "-njcx"
jfischer_link110{at}attbi-njcx.com

 
 
 

help me!! sed command.

Post by somez7 » Thu, 19 Sep 2002 02:48:57


Thanks you very much for you kind explain.
Have a day.



> > Hi ,all

> > I'm reading a book regarding linux.
> > I meet sed command as follows
> >     sed  's%\$(PERL)%/usr/bin/perl%'  Makefile > Makefile.backup
> > here I'd like to know the meaning of  1th % sign , 2nd % sign 3th %
sign.
> > Could some explain me. what's the meaning of each % signs


> command, e.g.,

>     s/a/b/

>     s%a%b%

> For example, try searching for the string '/usr/bin/perl' using the s///
> syntax:

>      echo "/usr/bin/perl" | sed 's/\/usr\/bin\//hello /' -

> This is too much work! :-\

> But if you use a field delimiter character other than '/' with sed's 's'

> command that manipulates input strings containing the '/' character:

>      echo "/usr/bin/perl" | sed 's%/usr/bin/%hello %' -

> --
> Jim

> To reply, please remove "_link" and "-njcx"
> jfischer_link110{at}attbi-njcx.com

 
 
 

help me!! sed command.

Post by Kasper Dupon » Fri, 20 Sep 2002 04:03:31




> command, e.g.,

>     s/a/b/

>     s%a%b%

Actually a lot of other chars could be used as well, ssasbs also
works. But of course you should always try choosing a char that
will make the statement as readable as possible.

--
Kasper Dupont -- der bruger for meget tid p? usenet.


 
 
 

1. replace gnu sed command ~ with sed command

Hi,

I've written a little sed script which is working in my environment. But
  I tried it in another environment and there it didn't work because the
~ command was unknown there.

Here the script:
# beginning at line 3, remove every 8th line
# beginning at line 4, remove every 8th line
# beginning at line 5, remove every 8th line
# beginning at line 6, remove every 8th line
sed -e '3~8d
         4~8d
         5~8d
         6~8d' file1.txt > file2.txt

How could I replace this gnu sed command with a sed command which is
valid in all environments?

I tried different things, but they didn't work.

For example I tried to replace this command as follows:

sed -e '3,${d;n;n;n;n;n;n;n}
         4,${d;n;n;n;n;n;n;n}
         5,${d;n;n;n;n;n;n;n}
         6,${d;n;n;n;n;n;n;n}' file1.txt > file2.txt

What am I doing wrong?

I'm new to sed, but I really like it and want to learn more about it and
I'm very interested in your answers.

Thanks for your help

Dirk

2. Value of Target Id when Lun spans disks

3. String manipulation error & how to use sed in a sed command?

4. tcpserver question

5. Need Help with SED command

6. FancyIndexing with Apache

7. sed command help

8. awk pipe delimited data -- and sed also (cpm)

9. Newbie needs help with sed command

10. Help request: SED insert command

11. HELP: sed command

12. HELP with SED Command

13. Need Help with "sed" command