Interesting problem

Discussion in 'Programming' started by supamanjon, Mar 25, 2008.

  1. #1
    Not sure if this is right place but let's say i have a txt file

    with keywords

    keyword1
    keyword2
    keyword3

    and i want to put commas after each one so it wil be
    keyword1,
    keyword2,
    keyword3,


    How do i do that besides typing the actual , after eahc word. That would take years for a fewhundred keywords?
     
    supamanjon, Mar 25, 2008 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Read the text file into a string variable, use a replace command to replace the carrage return/ line feed with a comma followed by a carrage return, write the string to a new text file.
     
    AstarothSolutions, Mar 25, 2008 IP
  3. it career

    it career Notable Member

    Messages:
    3,562
    Likes Received:
    155
    Best Answers:
    0
    Trophy Points:
    270
    #3
    Use tr -s "\n" "\n," in an unix shell.
     
    it career, Mar 26, 2008 IP
  4. ahmadfarhan

    ahmadfarhan Peon

    Messages:
    211
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    should be
    tr -s "\n" ",\n"
    me thinks..
     
    ahmadfarhan, Jul 1, 2008 IP