Results 1 to 5 of 5

Thread: Why does `sed '' filename` print the file to screen?

  1. #1
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,471
    Distro
    Lubuntu 14.04 Trusty Tahr

    Why does `sed '' filename` print the file to screen?

    If I have a file called "filename" and run sed '' filename, the contents of "filename" appear on the screen. Why is that?
    de gustibus et coloribus non est disputandum -- Wiktionary

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Why does `sed '' filename` print the file to screen?

    sed streams file but modifies it on the fly using these programs/expressions you usually provide. If you provide empty program, no change happens and the file is printed to the screen verbatim.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,471
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Why does `sed '' filename` print the file to screen?

    Quote Originally Posted by Vaphell View Post
    sed streams file but modifies it on the fly using these programs/expressions you usually provide. If you provide empty program, no change happens and the file is printed to the screen verbatim.
    In other words, in something like
    Code:
    sed OPTIONS SCRIPT/COMMANDS INPUTFILE
    the SCRIPT/COMMANDS would be within ' and ' but just an empty '' tells sed to print INPUTFILE to screen verbatim and that is because "print" is the default when nothing else is specified or when "print" is not specifically excluded from being default by use of -n.

    Would my understanding be correct?
    de gustibus et coloribus non est disputandum -- Wiktionary

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Why does `sed '' filename` print the file to screen?

    yes.
    Technically the script/commands part doesn't have to be within '' or "", all you have to make sure is that shell passes that part as a single parameter. Quotes are merely the most convenient way to do that but you can escape all chars related to shell syntax eg whitespace, semicolons etc.

    Code:
    $ sed -n p\;s/\ /=/g\;p <( echo a b c )
    a b c
    a=b=c
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  5. #5
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,471
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Why does `sed '' filename` print the file to screen?

    Thank you! Marked "Solved"
    de gustibus et coloribus non est disputandum -- Wiktionary

Bookmarks

Posting Permissions

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