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 -->
  #4 (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.

Thanks to ZB for pointing out the part I apparently skipped over. If that is desired, then the sed becomes slightly more complex (or mysterious), and it is easier to build it into a separate sed script file:

% cat s3
Code:
#!/bin/sh

# @(#) s3       Demonstrate sed line split and merge.

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

FILE=${1-data1}

echo
echo " Input file:"
nl $FILE

cat >script <<'EOF'
/==Document$/{
N
s/==Document\n/==\nDocument/
}
EOF

echo
echo " Output"
sed -f script $FILE |
nl

exit 0
producing:
Code:
% ./s3
 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
     1  Beginning.
     2  This is a test set of data.
     3  ==============
     4  this is ok.
     5  ==============
     6  this is ok, too.
     7  =============
     8  Documentthis we want changed.
     9  =============
    10  this is ok again.
    11  End
With help from O'Reilly sed & awk, 2nd, Chapter 6 ... cheers, drl
Reply With Quote