+ Reply to Thread
Results 1 to 3 of 3

Thread: Bash: Add Linebreak after character in text

  1. #1
    Jordan Guest

    Bash: Add Linebreak after character in text

    I use this little script for EDI parsing. It will add a linebreak after a character it finds.

    Code:
    #!/bin/sh -vx
    
    # Script to add line breaks after the delimiter of an EDI file.
    # Paramters:    filename    input file (edi data file)
    #               output      file to be written
    #               delimiter   ending delimiter of EDI file (\, *, ~, etc)
    ############################################################################
    
    # Variables
    filename=$1
    output=$2
    delim=$3
    replace='s/'$delim'/\n/g'
    
    cat $1 | tr -d "\n" > $output.br4
    cat $output.br4 | sed -e $replace > $output
    Usage:
    Code:
    # linebreak.sh <filename> <output filename> <delimiter>
    Text Sample:
    Code:
    v1,v2*v3,v4*v5,v46*
    Example:
    Code:
    # linbreak.sh /example.txt /example_parsed.txt \*
    Note: You have to escape special characters

    Output:
    Code:
    v1,v2*
    v3,v4*
    v5,v46*

  2. CODECALL Circuit advertisement

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    How many languages did you write this EDI parser in?

  4. #3
    Jordan Guest
    This isn't an EDI parser but a customized program for an ERP program we have. It was unable to handle reading text files without linebreaks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 10-12-2011, 06:24 AM
  2. Bash
    By Hunter100 in forum Linux/Unix General
    Replies: 3
    Last Post: 02-12-2010, 09:41 AM
  3. bash hacks
    By DarkLordoftheMonkeys in forum Linux Tutorials, Guides and Tips
    Replies: 3
    Last Post: 12-03-2009, 01:37 PM
  4. BASH: FTP Put Script
    By Jordan in forum Bash / Shell Scripting
    Replies: 12
    Last Post: 11-11-2009, 10:26 AM
  5. What is bash?
    By LemonMan in forum Linux/Unix General
    Replies: 3
    Last Post: 01-26-2009, 08:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

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