Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Join Date
    Aug 2007
    Posts
    11

    Red face Unanswered: unix command for add text

    anabody can help to solved my problem....

    i want to add text to the first line and last line. Can anobody tell me what the unix command that i can use...
    This is for example output that i want

    abcde|||||||
    fghijk
    lmnop
    qrstu|||||||

    red line that part i want to add....

  2. #2
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Quote Originally Posted by erin_0502
    anabody can help to solved my problem....

    i want to add text to the first line and last line. Can anobody tell me what the unix command that i can use...
    This is for example output that i want

    abcde|||||||
    fghijk
    lmnop
    qrstu|||||||

    red line that part i want to add....
    Assuming that you want a pipe as indicated in your example:
    Code:
    sed 's/$/|/'
    You must use the single quotes for this to work.

  3. #3
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    To complete the sed command to meet the requirements:
    Code:
    sed -e '1s/$/|||||||/' -e '$s/$/|||||||/'
    Regards

  4. #4
    Join Date
    Aug 2007
    Posts
    11

    Red face

    thank for all attention.......
    can u help me to teach me how can i try to using sed command because i new one in informix.....

  5. #5
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Quote Originally Posted by erin_0502
    thank for all attention.......
    can u help me to teach me how can i try to using sed command because i new one in informix.....
    What exactly are you trying to do? I don't see where informix ties into sed.

  6. #6
    Join Date
    Aug 2007
    Posts
    11
    opppsss sory....
    thank for all of you, that command can solve my problem....but now i must to create simple coding to use this command....can anobody give me example coding using this command??????????

  7. #7
    Join Date
    Aug 2007
    Posts
    11
    hello.................
    i can solved third promblem now....
    can anobody help me, how to save that file....now when i run i get the correct output, but i view from file the file still come out without change anything. so i think this is because i don,t save yhat line into file....
    help me plz....

  8. #8
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Quote Originally Posted by erin_0502
    hello.................
    i can solved third promblem now....
    can anobody help me, how to save that file....now when i run i get the correct output, but i view from file the file still come out without change anything. so i think this is because i don,t save yhat line into file....
    help me plz....
    You can redirect the output to a file like this:
    Code:
    sed 's/$/|/' > file
    My UNIX does not require the "e" switch. Take your sed command and redirect it with the ">"

  9. #9
    Join Date
    Aug 2007
    Posts
    11
    i try to using that command but that is nothing...
    but now when i run i get this syntax......

    sed: command garbled: $s/$/|||||||//home3/users/bcs02/irni/txtfile/a.txt

    MAIN
    DEFINE
    path CHAR(225),
    sed CHAR(225)

    LET path = "/home3/users/bcs02/irni/txtfile/a.txt"

    LET sed = "\\sed -e '1s/$/|||||||/' -e '$s/$/|||||||/'", path
    LET sed = sed CLIPPED

    RUN sed

    END MAIN
    ~
    this is my simple coding.. can u help me.......i don't no what the problem...

  10. #10
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Erin, what operating system are you using? UNIX or a linux distro?

  11. #11
    Join Date
    Aug 2007
    Posts
    11
    i using UNIX....

  12. #12
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Erin,

    I am not certain if you can run a UNIX command from within a static sql statement like you are trying to do. I can help you with UNIX but I don't know how to tell you to call it from your script. I'm sorry.

  13. #13
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    Hi Erin,

    First, the -e option with GNU sed means 'expression' and it's use with more than one expression in a Linux distribution is mandatory. Check in the man pages of your system what flag, if any, should be used. I believe Solaris sed uses the flag in the same way but I know AIX sed doesn't need a flag for this.
    Second, you'd better check the UNIX shell script community for questions about sed because it's a pure OS tool, not an Informix one.
    But since you've pasted it in 4GL I can give you the following example.
    Code:
    LET path = "/home3/users/bcs02/irni/txtfile/a.txt" 
    LET sed = "\\/usr/bin/sed -e '1s/$/|||||||/' -e '$s/$/|||||||/' >", path 
    LET sed = sed CLIPPED 
    RUN sed
    Comment:
    The systemcommand RUN tries to execute needs to be of the same form as when executed from the commandline, so why do you write a backslash in front of sed?
    Code:
    LET sed = "sed -e ..."
    will probably work OK, but better is to use the fullpathname of the command, which can be obtained on the commandline with
    Code:
    which sed
    that shows the exact location of the sed program, usualy /bin or /usr/bin.

    To redirect the stdout of sed (or any command in UNIX) to a file use '> filename' for a creating a new file (or overwriting one if it already exists) or '>> filename' for appending to an existing one (or creating a new one if it doesn't exist).
    You don't have to undo the variable (with CLIPPED) from it's trailing spaces; the shell that's executing the sed command will ignore them automatically.

    That should be it, try the command first on the commandline and if it works past it into the 4GL program.

    Regards
    Last edited by Tyveleyn; 08-27-07 at 07:13.

  14. #14
    Join Date
    Aug 2007
    Posts
    11

    Red face

    i still have problem....
    when i used ">" in my coding, nothing come out and output in filename empty...i try to using sed -n '/1s/,/$s/w out' input-file also cannot....
    why in program ok when i run but not come out in filename... i think i pass the value to correct path...

  15. #15
    Join Date
    Aug 2007
    Posts
    11

    Red face

    i still have problem....
    when i used ">" in my coding, nothing come out and output in filename empty...i try to using sed -n '/1s/,/$s/w out' input-file also cannot....
    why in program ok when i run but not come out in filename... i think i pass the value to correct path...

Posting Permissions

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