Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I have the file 'file.txt' : nadal federer delpotro I want to use the append line command 'a\' of 'sed' to append the 2 following lines: wimbledon USopen after ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    1

    sed : difference csh/sh to append a line



    Hi,

    I have the file 'file.txt' :

    nadal
    federer
    delpotro

    I want to use the append line command 'a\' of 'sed' to append the 2 following lines:

    wimbledon
    USopen

    after the 'federer' line

    under sh, I execute :
    $ sed '/federer/a\
    > wimbledon\
    > USopen' file.txt

    Result OK :
    nadal
    federer
    wimbledon
    USopen
    delpotro

    To get the same result under csh, I have to execute :
    sed '/federer/a\\
    ? wimbledon\\
    ? USopen' file.txt

    why do I have to double the '\' character ?
    Is it related to the shell ? the sed program (I am using the same GNU version 4.0.7 under Linux) ?

    Any idea ?

    thanks

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    109
    Quote Originally Posted by larrun View Post
    Hi,

    I have the file 'file.txt' :

    nadal
    federer
    delpotro

    I want to use the append line command 'a\' of 'sed' to append the 2 following lines:

    wimbledon
    USopen

    after the 'federer' line

    under sh, I execute :
    $ sed '/federer/a\
    > wimbledon\
    > USopen' file.txt

    Result OK :
    nadal
    federer
    wimbledon
    USopen
    delpotro

    To get the same result under csh, I have to execute :
    sed '/federer/a\\
    ? wimbledon\\
    ? USopen' file.txt

    why do I have to double the '\' character ?
    Is it related to the shell ? the sed program (I am using the same GNU version 4.0.7 under Linux) ?

    Any idea ?

    thanks
    Hi larrun
    I have taken a snippet from the man pages of 'sh' and from 'csh' to possibly help understand the reason. Different 'Parser Engines' are used for sh and csh (possibly tcsh).

    sh
    When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by $, `, or \. The first backquote not preceded by a backslash terminates the command substitution. When using the $(command) form, all characters between the parentheses make up the command; none are treated specially.

    csh
    A special character (including a blank or tab) may be prevented from having its special meaning, and possibly made part of another word, by pre-ceding it with a backslash (‘\’) or enclosing it in single (‘’’), double (‘"’) or backward (‘‘’) quotes. When not otherwise quoted a newline preceded by a ‘\’ is equivalent to a blank, but inside quotes this sequence results in a newline.
    I believe that the issue is a function of the Shells and not 'sed'. Not sure that this is exactly what you are looking for but may help in some way. Cheers...
    Robert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •