Cut specific column from 2 file and merge

Hi ALL,

I have two file. I need to combine these two file based on a layout.

I used the below code and able to extract the record. But now able to insert that to a 3'rd file in between the extract

FILE 1

CAID NUMBER 1-20
TID   NUMBER 21-22
LABEL CHAR    23-44
BASE               45-60

FILE 2

 CCODE NUMBER 1-20
CCID    NUMBER 21-40

MERGE FILE

 CAID NUMBER 1-20
TID   NUMBER 21-22
LABEL CHAR    23-44
CCODE NUMBER 45-65
BASE               66-81
awk '{print ((substr($0,1,20))) "," ((substr($0,21,22))) "," ((substr($0,23,44))) "," ((substr($0,45,60)))}'    FILE1
awk '{print ((substr($0,1,20))}'    FILE1

Thanks,
Arun

Please explain the logics. Based on what is the line

CCODE NUMBER 45-65

adapted and inserted the way you post?

EDIT: I guess you want to extract data from OTHER files based on the "record description" in FILE1 and FILE2 (which would not be correctly done by your script). Still my question persists...

Basically , I want to join the two file.

Extract all record from file 1. Record1 Record2 Record3 Record4 from file and Extract Record2 from file2
The combined file will be like Record1 Record2 Record3 Record2(file2) Record4

Thanks,
Arun

Man is your friend :

man join
man paste

Did you try something like :

ksh paste -d# <(cut -c1-44 FILE1 ) <(cut -c1-20 FILE2) <(cut -c45-60 FILE1)

Here i have set # as delimiter , choose one which does not already occur in your file so you can easy get rid off of it adding a | sed 's/#//g'

Getting the below error.

ksh paste -d# <(cut -c93-113 20160010101110.dat )
paste: paste: cannot execute [Exec format error]

Ok then give a try splitting into short steps like:

cut -c1-44 FILE1 >f1
cut -c1-20 FILE2 >f2
cut -c45-60 FILE1 >f3
paste -d# f1 f2 f3 | sed 's/#//g' | tee MERGEFILE
rm f?