Concatenating multiple records into a single record

Concatenating multiple records into a single record

Post by Jeremy Ovende » Mon, 08 Nov 1999 04:00:00



Is there a simple (i.e. for a real unix rookie) to create a single record
(in a new file) from multiple records in a source file?

For example, let us say we have the folloiwng file contents

aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
###
eeeeeeee
ffffffff
gggggggg
hhhhhhhh
###

etc.
and what I want is a file that contains

aaaaaaaabbbbbbbbccccccccdddddddd
eeeeeeeeffffffffgggggggghhhhhhhh

The ### is to indicate some recognisable delimiter.

Can anyone help?

Best regards
Jeremy Ovenden

 
 
 

Concatenating multiple records into a single record

Post by Charles Dem » Mon, 08 Nov 1999 04:00:00




>Is there a simple (i.e. for a real unix rookie) to create a single record
>(in a new file) from multiple records in a source file?

>For example, let us say we have the folloiwng file contents

>aaaaaaaa
>bbbbbbbb
>cccccccc
>dddddddd
>###
>eeeeeeee
>ffffffff
>gggggggg
>hhhhhhhh
>###

>etc.
>and what I want is a file that contains

>aaaaaaaabbbbbbbbccccccccdddddddd
>eeeeeeeeffffffffgggggggghhhhhhhh

>The ### is to indicate some recognisable delimiter.

awk '/^###/ {print "";next}{printf "%s", $0}' infile

This assumes each block of lines to be joined is followed by
a "###" line.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.


 
 
 

Concatenating multiple records into a single record

Post by Ken Pizzi » Mon, 08 Nov 1999 04:00:00


On Sun, 7 Nov 1999 11:19:24 -0000,


>Is there a simple (i.e. for a real unix rookie) to create a single record
>(in a new file) from multiple records in a source file?

>For example, let us say we have the folloiwng file contents

>aaaaaaaa
>bbbbbbbb
>cccccccc
>dddddddd
>###
>eeeeeeee
>ffffffff
>gggggggg
>hhhhhhhh
>###

>etc.
>and what I want is a file that contains

>aaaaaaaabbbbbbbbccccccccdddddddd
>eeeeeeeeffffffffgggggggghhhhhhhh

>The ### is to indicate some recognisable delimiter.

sed '/^###$/!{H;d;};g;s/.*//;x;s/\n//g' source > dest

Hmmm... okay, I guess that isn't really a rookie-simple command.
Try the awk or perl solutions (that others posted) instead.

                --Ken Pizzini

 
 
 

Concatenating multiple records into a single record

Post by chris ulri » Tue, 09 Nov 1999 04:00:00



%%Is there a simple (i.e. for a real unix rookie) to create a single record
%%(in a new file) from multiple records in a source file?
%%
%%For example, let us say we have the folloiwng file contents
%%
%%aaaaaaaa
%%bbbbbbbb
%%cccccccc
%%dddddddd
%%###
%%eeeeeeee
%%ffffffff
%%gggggggg
%%hhhhhhhh
%%###
%%
%%etc.
%%and what I want is a file that contains
%%
%%aaaaaaaabbbbbbbbccccccccdddddddd
%%eeeeeeeeffffffffgggggggghhhhhhhh
%%
%%The ### is to indicate some recognisable delimiter.
%%Jeremy Ovenden

entirely within posix sh/ksh/bash:

while
  read -r line
do
  case "$line" in
    ###)
        echo "$fullrecord"
        fullrecord=
       ;;
    *)
        fullrecord="$fullrecord$line"
       ;;
  esac
done
echo "$fullrecord"

  If you don't have access to a posix shell, omit the -r on the first read.
chris