#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    8
    Rep Power
    0

    Question replace "|" with empty space


    Hi!

    I have a problem with the special character "|". The problem is in subject feild it is displaying

    abc@def.com|efg@ijk.com|.....

    i have to replace the "|" with blank space can you help me out please it is very very urgent for me

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    USA
    Posts
    334
    Rep Power
    12
    Assuming that you have a file containing these '|'s then
    probably the easiest way to fix the problem is to use
    sed(1) i.e.

    sed -e 's/\|/ /g' filename

    or to save output to a file

    sed -e 's/\|/ /g' filename > newfilename

    - Finnbarr
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    8
    Rep Power
    0
    Hi! Finnbarr,
    Thanks for your help but when i use this command direct to the file it is giving an error as sed: command garbled: s/\|/ /g, or if i save this out put to a new file and use that file then it is not even displaying the error:Can't open filename. if you can please help me out in fixing this issue
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    137
    Rep Power
    0
    Finnbarr's commands are correct. With some *nix flavors you don't have to 'escape' the pipe charachter ( | vs \| ).

    Are you trying to do this from the command line or a shell script?

    Can you post the code you tried to execute that failed?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    8
    Rep Power
    0
    Hi! Finnbarr's,
    Thanks for your response here is part of script which im trying to execute
    1)SUBJECTLN="`date +%m/%d/%y::%H:%M`:Order Activity Report ("
    2)SUBJECT=$SUBJECTLN$gxi")"
    where gxi is a text file with information stored as
    abc|efg|.....
    3)mailx -s "$SUBJECT" "$ADDRESSES"

    now in subject field it is printing as

    OUTPUT

    01/26/04::11:44:Order Activity Report (abc|efg|.....)
    i should replace that pipe in (abc|efg|.....) and print as (abc efg ....).

    I tryed to use it in shell script rather than on command line but it is not working out for me.
    Last edited by riaz_mohd; January 27th, 2004 at 01:28 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    137
    Rep Power
    0
    This works on my box:
    Code:
    #!/bin/sh
    
    SUBJECTLN="`date +%m/%d/%y::%H:%M`:Order Activity Report ("
    
    # gxi is file (filled with Foo|Bar|Foo|Bar)
    gxi=/home/user/infile
    SUBJECT=$SUBJECTLN`sed -e 's/|/ /g' $gxi`")"
    echo $SUBJECT
    
    # gxi declared in script
    gxi="Foo|Bar"
    SUBJECT=$SUBJECTLN`echo $gxi | sed -e 's/|/ /g'`")"
    echo $SUBJECT
    The output is:
    01/27/04::19:41:Order Activity Report (Foo Bar Foo Bar)
    01/27/04::19:41:Order Activity Report (Foo Bar)

    As you can see I did not have to escape the pipe symbol.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    8
    Rep Power
    0
    Thanks it is working really fine
    Last edited by riaz_mohd; January 27th, 2004 at 02:56 PM.

IMN logo majestic logo threadwatch logo seochat tools logo