Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Suggestions for converting a text file format.

    I have a large text file over 40k lines in the format:

    Some Company
    999 N Oak Trfy,
    Kansas City,

    And would like to know of a way to change it to:

    Some Company, 999 N Oak Trfy, Kansas City, MO, 64118

    Any suggestions would be greatly appreciated.

  2. #2
    Use the tr command in bash.

    tr '\n' ' ' < /path/to/file > /path/to/newfile
    This will make all companies appear on the same line, but assuming you have a line break between companies, you can just run another script after the first one, which will replace double spaces with a new line.

    tr '  ' '\n' < /path/to/newfile > /path/to/newfile2
    Last edited by Cancerous; 09-26-2012 at 12:24 AM.

  3. #3
    Quote Originally Posted by Cancerous View Post
    tr '  ' '\n' < /path/to/newfile > /path/to/newfile2
    That will replace all spaces with a newline! tr works on sets of characters (try it for yourself: "echo ab | tr ab A"). To replace more than one character, you'd need sed. Following the suggestion above:

    sed 's.  .\n.g' oldfile > newfile
    However, if there isn't an extra line break between each record, you'll probably need a (quick) custom program.

  4. $spacer_open

Posting Permissions

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