AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
Expand all | Collapse all

How to comment multiple lines using sed command

  • 1.  How to comment multiple lines using sed command

    Posted Mon April 21, 2014 10:28 PM

    Originally posted by: zieggy


    Hi,

    I want to comment out lines in inetd.conf file highlighted in red, how can i do it using sed or awk command?

    Thanks

    ##      protocol.  "tcp" and "udp" are interpreted as IPv4.
    ##
    ## service  socket  protocol  wait/  user    server    server program
    ##  name     type             nowait         program     arguments
    ##
    ftp     stream  tcp6    nowait  root    /usr/sbin/ftpd         ftpd
    telnet  stream  tcp6    nowait  root    /usr/sbin/telnetd      telnetd -a
    shell   stream  tcp6    nowait  root    /usr/sbin/rshd         rshd
    #kshell  stream  tcp     nowait  root    /usr/sbin/krshd        krshd
    login   stream  tcp6    nowait  root    /usr/sbin/rlogind      rlogind
    #klogin  stream  tcp     nowait  root    /usr/sbin/krlogind     krlogind
    exec    stream  tcp6    nowait  root    /usr/sbin/rexecd       rexecd
    #comsat dgram   udp     wait    root    /usr/sbin/comsat       comsat
    #uucp   stream  tcp     nowait  root    /usr/sbin/uucpd        uucpd
    #bootps dgram   udp     wait    root    /usr/sbin/bootpd       bootpd /etc/bootptab
     

     

     



  • 2.  Re: How to comment multiple lines using sed command

    Posted Wed April 23, 2014 04:52 AM

    Originally posted by: Wouter Liefting


    Various options. Here's one:

    sed 's/^ftp /#ftp /' /etc/inetd.conf > /etc/inetd.conf.new && rm /etc/inetd.conf && mv /etc/inetd.conf.new /etc/inetd.conf

    Perl inline editing makes it easier but the regex is the same.

    perl -pi -e 's/^ftp /#ftp /' /etc/inetd.conf

    But both of these are not really recommended. There is a chinet command specifically for this. I don't have an AIX machine to hand so I can't give you the exact syntax, but try a smitty chinet, and use F6 to see what command is being run.