The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 07-04-2007
drl's Avatar
drl drl is offline
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 580
Hi.

Here is one solution:
Code:
#!/bin/sh

# @(#) s1       Demonstrate sed line split.

set -o nounset
echo " sh version: $BASH_VERSION" >&2
sed --version | head -1

FILE=${1-data1}

echo
echo " Input file:"
nl $FILE

echo
echo " Output"
sed 's/^\(.*====\)\(Document.*\)$/\1\n\2/' $FILE

exit 0
producing:
Code:
% ./s1
 sh version: 2.05b.0(1)-release
GNU sed version 4.1.2

 Input file:
     1  Beginning.
     2  This is a test set of data.
     3  ==============
     4  this is ok.
     5  ==============
     6  this is ok, too.
     7  =============Document
     8  this we want changed.
     9  =============
    10  this is ok again.
    11  End

 Output
Beginning.
This is a test set of data.
==============
this is ok.
==============
this is ok, too.
=============
Document
this we want changed.
=============
this is ok again.
End
cheers, drl
Reply With Quote