Desire structure for input file

Hello Unix gurus,

I have a txt file with single columns with n no of rows.like below

COLUMN1

AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
.
.
.
NNN.

i need to iterate the above input for row count (row count is not fixed).The out put structure should be like below in between special characters

are required to add to oupt put like (<> ,A. ,B.) .

o/p
----

A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
.
.
.
A.NNN <> B.NNN;

Can any body suggest how to write this using scripting.

sed 's/.*/A.& <> B.& or/; $s/ or$/;/'

Example:

$ cat data
AAA
BBB
CCC
DDD
EEE
FFF
GGG
HHH
$ sed 's/.*/A.& <> B.& or/; $s/ or$/;/' data
A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF or
A.GGG <> B.GGG or
A.HHH <> B.HHH;

Regards,
Alister

awk '{print "A." $1 " <> B." $1 " or "}' infile
$ ruby -ne 'BEGIN{s=""};print s if s;s=gsub(/^(.*)$/,"A.\\1 <> B.\\1 or");END{puts s.strip.gsub("or","")+";"}' file
A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF or
A.GGG <> B.GGG or
A.HHH <> B.HHH ;


Hello Alister,

Thanks for your inputs.I have executed the command which u suggested.

======================
more test.txt
AAA
BBB
CCC
DDD
EEE
FFF

"test.txt" 7L, 25C written
sl000247:/db2mig/data/back_out $ sed 's/.*/A.& <> B.& or/; $s/ or$/;/' test.txt
A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF or
A. <> B.;

observe the last 2 lines i have the last line in my input file is FFF

so in the ouput we should get like ..

A.AAA <> B.AAA or
A.BBB <> B.BBB or
A.CCC <> B.CCC or
A.DDD <> B.DDD or
A.EEE <> B.EEE or
A.FFF <> B.FFF ;

---------- Post updated at 02:38 AM ---------- Previous update was at 02:33 AM ----------

Hello kurumi,

i could not able to find out ruby on bash.

ruby -ne 'BEGIN{s=""};print s if s;s=gsub(/^(.*)$/,"A.\\1 <> B.\\1 or");END{puts s.strip.gsub("or","")+";"}' test.txt
-bash: ruby: command not found

Take a look at your data file with `od` or `hexdump` or `vis` or `sed -n l` or `cat -vet` and you'll probably find some character that doesn't show up on your terminal; that's almost certainly the source of the extra line at the end of my sed suggestion's output. Perhaps it's a stray carriage return or other control character?

Also, your sample output in your most recent post differs from that of your original post. The latter has a space before the final semi-colon; the former does not. If you want that space, use this slightly modified version of my original suggestion:

sed 's/.*/A.& <> B.& or/; $s/or$/;/'

Regards,
Alister

Hello Alister,

Thanks the latest post work for me .

Appriciate your help.

Regards
kanaka

---------- Post updated at 05:43 AM ---------- Previous update was at 02:52 AM ----------

Hello Alister,

I started using our sed in my script.

i have file report3.txt with content

more report3.txt


AAAA
BBBB
CCCC
..
..
XXXX
YYYY
ZZZZ

26 record(s) selected.

when i use our sed command now the results is displazing 2 more lines in the begining and 1 more line extra in the bottom.

A. <> B. or
A. <> B. or
A.-------------------- <> B.-------------------- or
A.AAA <> B.AAA or
..
..
A.ZZZ <> B.ZZZ or
A. <> B. or
A. 26 record(s) selected. <> B. 26 record(s) selected. or
A. <> B. ;

I don't want the lines in red colour should be display in my output .any suggessions how to discard those line while printing?

awk '!(/^$/||/--/||/selected/){print "A." $1 " <> B." $1 " or"}' infile |sed '$ s/ or$/;/'

awk '!(/^$/||/--/||/selected/){print "A." $1 " <> B." $1 " or"}' report3.txt |sed '$ s/ or$/;/'
A. <> B. or
A.AAA<>B.AAA or
A.BBB<>B.BBB or
.
..
..
A.ZZZ<>B.ZZZ;

Now its better than previous. still one more row at the top now

I guess there is blank space in first line:

awk '!(/^$/||/--/||/selected/||/^ *$/){print "A." $1 " <> B." $1 " or"}' report3.txt |sed '$ s/ or$/;/'

If the following doesn't work, you need to provide a more accurate account of what's in the file using something like `od -c`:

grep -Ev '^[[:space:]]*$|^--*$|record\(s\) selected' data | sed 's/.*/A.& <> B.& or/; $s/or$/;/'

Regards,
Alister

---------- Post updated at 08:07 AM ---------- Previous update was at 08:03 AM ----------

Alternatively, if a stream is not required and the result will be saved to a new file, ed can be used:

#!/bin/sh

# Usage: scriptname source-file destination-file

src=$1
dest=$2

ed -s "$src" <<EOED
    g/^[[:space:]]*$/d
    g/^--*$/d
    /record(s) selected/d
    1,\$s/.*/A.& <> B.& or/
    \$s/or/;/
    w $dest
    q
EOED