Jump to content

Bash: Add Linebreak after character in text

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Guest_Jordan_*

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

#!/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:
# linebreak.sh <filename> <output filename> <delimiter>

Text Sample:
v1,v2*v3,v4*v5,v46*

Example:
# linbreak.sh /example.txt /example_parsed.txt \*

Note: You have to escape special characters

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


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
How many languages did you write this EDI parser in?

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
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.