Find the answer to your Linux question:
Results 1 to 3 of 3
Hi to all! I haven't understand something about sed. If i launch the command 'sed -f filescript text' , where filescript: Code: #!/usr/bin/sed -f # Put 80 spaces in the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2012
    Posts
    2

    Question sed problems


    Hi to all! I haven't understand something about sed.
    If i launch the command 'sed -f filescript text' , where filescript:
    Code:
    #!/usr/bin/sed -f    
    # Put 80 spaces in the buffer
    1{
      x
      s/^$/        /
      s/^.*$/&&&&&&&&/
      x
     }
    # del leading and trailing spaces
    y/\t/ /
    s/^ *//
    s/ *$//
    # add a newline and 80 spaces to end of line
    G
    and text:
    Code:
     
     one
     two
    (there are two initial spaces on every line)
    Sed put the first line in the pattern buffer by removing \n. After switches the two buffers and so the pattern buffer has 80 spaces and the hold buffer has " one".After it switches the buffers, so " one" is on pattern space. sed removes the leading zero, so the pattern buffer is now "one". After, with 'G' command it put \n and appends the 80 spaces to the pattern buffer. It finally prints the pattern buffer in the stdout,move the pattern buffer in hold buffer and start with the second line of the input,i.e. " two".Here it removes only the leading zero, so the pattern buffer is "two".After with 'G' it put \n in the pattern buffer and appends to it the hold buffer (which is "one\n[80 spaces]"). In the stdout it should prints "two\none\n[80 spaces]", but it prints "two".Why?

  2. #2
    Just Joined!
    Join Date
    Jul 2012
    Posts
    5
    Hi,

    Not sure exactly what you are intending to do, however when I run your script as you've spec'd above I get the following:
    -------------------------------------------------
    # sed -f filescript text


    one

    two

    #
    ---------------------------------
    I pushed the output to a file........
    # sed -f filescript test > output
    # vi output (and from within the file I ':set list' which shows all the 'special characters'.
    output.jpg

    ----------------
    I had to attach an image as the copy/paste wouldn't show the 'spaces'.

    I suggest you run your program with the > output (or a filename of your choice) and edit with 'vi' and :set list to see the special characters.

    Cheers
    Last edited by caburtenshaw; 09-04-2012 at 04:50 AM. Reason: Spaces didn't appear as copied.

  3. #3
    Just Joined!
    Join Date
    Sep 2012
    Posts
    2
    I've just solved! Thanks anyway!

Posting Permissions

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